Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 14:24
    Hypfer commented #1650
  • 09:05
    samtstern commented #1636
  • 08:53
    guillempuig edited #1653
  • 08:30
    guillempuig edited #1653
  • 08:29
    guillempuig labeled #1653
  • 08:29
    guillempuig opened #1653
  • Jun 17 19:27
    asnaseer-resilient commented #1652
  • Jun 17 19:24
    asnaseer-resilient commented #1652
  • Jun 17 19:20
    asnaseer-resilient commented #1652
  • Jun 17 19:19
    asnaseer-resilient commented #1652
  • Jun 17 18:51
    epoberezkin commented #1652
  • Jun 17 18:51
    epoberezkin commented #1652
  • Jun 17 18:51
    epoberezkin commented #1652
  • Jun 17 18:42
    asnaseer-resilient edited #1652
  • Jun 17 18:06
    asnaseer-resilient commented #1652
  • Jun 17 17:50
    epoberezkin commented #1652
  • Jun 17 17:47
    epoberezkin commented #1636
  • Jun 17 15:46
    asnaseer-resilient labeled #1652
  • Jun 17 15:46
    asnaseer-resilient opened #1652
  • Jun 17 14:10
    samtstern commented #1636
Evgeny Poberezkin
@epoberezkin
what's npm version?
paul-uz
@paul-uz
8.2.0
oh sorry
Evgeny Poberezkin
@epoberezkin
no, npm's
paul-uz
@paul-uz
7.6.0
Evgeny Poberezkin
@epoberezkin
I have the same in tests
paul-uz
@paul-uz
try that zip
Evgeny Poberezkin
@epoberezkin
but github CI uses v6, there is some nonsence with peer deps, so I am using v6...
paul-uz
@paul-uz
in VSCode, it shows the error
Evgeny Poberezkin
@epoberezkin
hm
paul-uz
@paul-uz
this is the code in ajv.d.ts...
Evgeny Poberezkin
@epoberezkin
send the issue pls
paul-uz
@paul-uz
import type { AnySchemaObject } from "./types";
import AjvCore from "./core";
declare class Ajv extends AjvCore {
_addVocabularies(): void;
addDefaultMetaSchema(): void;
defaultMeta(): string | AnySchemaObject | undefined;
}
export default Ajv;
export { Format, FormatDefinition, AsyncFormatDefinition, KeywordDefinition, KeywordErrorDefinition, CodeKeywordDefinition, MacroKeywordDefinition, FuncKeywordDefinition, Vocabulary, Schema, SchemaObject, AnySchemaObject, AsyncSchema, AnySchema, ValidateFunction, AsyncValidateFunction, SchemaValidateFunction, ErrorObject, ErrorNoParams, } from "./types";
export { Plugin, Options, CodeOptions, InstanceOptions, Logger, ErrorsTextOptions } from "./core";
export { SchemaCxt, SchemaObjCxt } from "./compile";
export { KeywordCxt } from "./compile/validate";
export { DefinedError } from "./vocabularies/errors";
export { JSONType } from "./compile/rules";
export { JSONSchemaType } from "./types/json-schema";
export {
, str, stringify, nil, Name, Code, CodeGen, CodeGenOptions } from "./compile/codegen";
I have logged the issue
looks like i'll have to downgrade till you fix it
Evgeny Poberezkin
@epoberezkin
you can use .default - what's there to fix?
try that zip
it works here (npm version is 6.14.12)
also works with npm 7.11.1
Evgeny Poberezkin
@epoberezkin
(that is if I delete node_modules and package-lock.json and do clean install, I will not be investigating what's wrong in node_modules...)
Jens A
@ajcool2k
@epoberezkin the online meeting sounds super interesting. any chance that this is getting recorded for people that can't make it?
Evgeny Poberezkin
@epoberezkin
@ajcool2k should be interesting indeed :) it will be recorded.
Josh
@josh-hemphill

Does anyone have any suggestions on how to effectively create a generic wrapper JTD schema? When all objects have a standard base interface. e.g.

type ResWrapper<T> = {
    ok: 0 | 1;
    id?: string;
    data: T;
}

I can get the types to inherit just fine, but I haven't found a good way to get JTDSchemaType to let me wrap the schema itself.

Evgeny Poberezkin
@epoberezkin
JTD schemas support definitions - it might help. Otherwise you can just compose JS objects
@/all this is the video of the recent Ajv webinar if you want to catch up https://twitter.com/epoberezkin/status/1397304098886721540
arshad-akra
@arshad-akra

Hi guys Im migrating from v6 to v8 using the migration guide
while doing so, on the older version this seemed to work fine

const func = getSchema(schema)
func(obj,`#/${i}`)

now it shows a lint error that string is not assignable to DataValidationCxt
so I looked up the interfaces of the functions and they seemed to have changed a bit and I think it's not mentioned on the migration guide
Ajv.ValidateFunction
v6

  interface ValidateFunction {
    (
      data: any,
      dataPath?: string,
      parentData?: object | Array<any>,
      parentDataProperty?: string | number,
      rootData?: object | Array<any>
    ): boolean | PromiseLike<any>;
    schema?: object | boolean;
    errors?: null | Array<ErrorObject>;
    refs?: object;
    refVal?: Array<any>;
    root?: ValidateFunction | object;
    $async?: true;
    source?: object;
  }

v8

export interface ValidateFunction<T = unknown> {
    (this: Ajv | any, data: any, dataCxt?: DataValidationCxt): data is T;
    errors?: null | ErrorObject[];
    evaluated?: Evaluated;
    schema: AnySchema;
    schemaEnv: SchemaEnv;
    source?: SourceCode;
}
export interface DataValidationCxt<T extends string | number = string | number> {
    instancePath: string;
    parentData: {
        [K in T]: any;
    };
    parentDataProperty: T;
    rootData: Record<string, any> | any[];
    dynamicAnchors: {
        [Ref in string]?: ValidateFunction;
    };
}

so should I just move the next param of on my code to the data path to the instance path param ? or am I missing something
any help would be greatly helpfull

Evgeny Poberezkin
@epoberezkin
All parameters other than data are not supposed to be used from the application code, they are there for other schemas to call schemas in definitions, and not really documented…
Why are you passing the second parameter?
arshad-akra
@arshad-akra
oh okay thanks for the reply, but im fairly new to the code base and was learning it and I don't see why they were using the 2nd parameter too and giving it an index of the loop
zwx00
@zwx00
Hey, quick question... this is more related to json typedef than ajv, but not sure where else to ask... I have a tagged union (discriminator) but there's no properties particular to one type, and only the other types add new properties besides the discriminator property itself. AJV is forcing me to define at least some properties on every member of the union. Is there a clean workaround for this through which I can express an empty set of properties here, or will I have to add an ugly hack with an optional property that never gets used just so the validator runs?
Evgeny Poberezkin
@epoberezkin
Can’t you have empty properties: {}?
zwx00
@zwx00
$ ts-node node_modules/tape/bin/tape tests/**

/Users/bblokar/Development/uab/shared/javascript-packages/design-document-schema/node_modules/ajv/lib/compile/codegen/index.ts:814
  return args.reduce(andCode)
              ^
TypeError: Reduce of empty array with no initial value
    dependsOn: {
      discriminator: 'type',
      mapping: {
        customScalingDimensions: {
          properties: {
            dependencies: {
              elements: {
                type: 'string'
              }
            }
          }
        },
        canvasContext: {
          properties: {}
        }
      }
    },
this is the pertinent part of the schema
Is that a bug or is that just something that wholly unsupported by the spec itself?
zwx00
@zwx00
Hey, I realized it works with empty optionalProperties, but not with empty (required) properties
here's a reproduction
1st one works, second doesn't... I can file a bug report if you wish
Evgeny Poberezkin
@epoberezkin
Yes, it probably should work
Hassan Assaad
@hsnassaad
Does anyone have an idea how to build a schema that will validate properties types based on other properties values, like i am getting [{v: "hello"}, {v: true, d: boolean}, {v: ["h", "e", "l", "l", "o"], d: "list_of_strings"}] when v is string (the default value) d property is not available but when d is available the type needs to match the type of v
Evgeny Poberezkin
@epoberezkin
Check out dependencies keyword
Or if/then/else
Roy Keene
@rkeene

I just upgraded to ajv@8.6.0 from ajv@6.12.6; I've also added ajv-formats@2.1.0 and use the default export against an instance of ajv(), however I still get: strict mode: unknown keyword: "regex"

Code looks like:

const schema = {...};
const record = {...};

const ajv = require('ajv');
const ajv_formats = require("ajv-formats");
const validator = new ajv();
ajv_formats(validator);
const schema_validator = validator.compile(schema);
const result = schema_validator(record);
Evgeny Poberezkin
@epoberezkin
regex is not a standard keyword - it might be a mistake in the schema (or missing custom keyword definition) and it was quietly ignored in v6. you either need to disable strict mode or to fix the schema.
Roy Keene
@rkeene
Isn't that added when I added ajv-formats ( https://ajv.js.org/guide/formats.html ) ?
regex: tests whether a string is a valid regular expression by passing it to RegExp constructor.
Evgeny Poberezkin
@epoberezkin
format: regex - yes, but it seems to be used as keyword in the schema
Hassan Assaad
@hsnassaad
@epoberezkin thanks that works successfully