@atproto/lexicon 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,126 +1,2 @@
1
- import { ValidateFunction } from 'ajv';
2
- import { AdxSchemaDefinition } from './types.js';
3
- declare type SomeObject = Record<string, unknown>;
4
- export interface AdxRecordValidatorDescription {
5
- type: string | string[];
6
- ext?: string | string[];
7
- }
8
- export * from './types.js';
9
- /**
10
- * A compiled schema.
11
- */
12
- export declare class AdxSchema {
13
- def: AdxSchemaDefinition;
14
- id: string;
15
- validateRecord?: ValidateFunction;
16
- validateParams?: ValidateFunction;
17
- validateResponse?: ValidateFunction;
18
- get name(): string;
19
- constructor(def: AdxSchemaDefinition);
20
- }
21
- /**
22
- * A collection of compiled schemas.
23
- */
24
- export declare class AdxSchemas {
25
- schemas: Map<string, AdxSchema>;
26
- private _locale;
27
- get locale(): string;
28
- set locale(v: string);
29
- /**
30
- * Add a schema definition.
31
- */
32
- add(schemaDef: unknown): void;
33
- /**
34
- * Remove a schema definition.
35
- */
36
- remove(key: string): void;
37
- /**
38
- * Get a schema definition.
39
- */
40
- get(key: string): AdxSchema | undefined;
41
- /**
42
- * Create a record validator out of one or more schemas.
43
- */
44
- createRecordValidator(desc: string | string[] | AdxRecordValidatorDescription): AdxRecordValidator;
45
- /**
46
- * Create a view validator out of a schema.
47
- */
48
- createViewValidator(view: string): AdxViewValidator;
49
- }
50
- /**
51
- * Validates records using schemas.
52
- */
53
- export declare class AdxRecordValidator {
54
- private schemas;
55
- type: AdxSchema[];
56
- ext: AdxSchema[];
57
- constructor(schemas: AdxSchemas, type: AdxSchema[], ext: AdxSchema[]);
58
- /**
59
- * Returns detailed information about validity and compatibility.
60
- */
61
- validate(value: SomeObject): AdxValidationResult;
62
- /**
63
- * Provides a simple boolean check of validity.
64
- */
65
- isValid(value: any): boolean;
66
- /**
67
- * Like validate() but throws if validation fails.
68
- */
69
- assertValid(value: any): AdxValidationResult;
70
- }
71
- /**
72
- * Validates views using schemas.
73
- */
74
- export declare class AdxViewValidator {
75
- view: AdxSchema;
76
- constructor(view: AdxSchema);
77
- /**
78
- * Returns detailed information about validity and compatibility.
79
- */
80
- validateResponse(value: SomeObject): AdxValidationResult;
81
- /**
82
- * Provides a simple boolean check of validity.
83
- */
84
- isResponseValid(value: any): boolean;
85
- /**
86
- * Like validateResponse() but throws if validation fails.
87
- */
88
- assertResponseValid(value: any): AdxValidationResult;
89
- }
90
- export declare enum AdxValidationResultCode {
91
- Full = "full",
92
- Partial = "partial",
93
- Incompatible = "incompatible",
94
- Invalid = "invalid"
95
- }
96
- export declare class AdxValidationResult {
97
- code: AdxValidationResultCode;
98
- /**
99
- * The error message (if fatal)
100
- */
101
- error: string | undefined;
102
- /**
103
- * A collection of all fallback messages
104
- */
105
- fallbacks: string[];
106
- /**
107
- * A collection of all messages
108
- */
109
- messages: string[];
110
- get valid(): boolean;
111
- get fullySupported(): boolean;
112
- get incompatible(): boolean;
113
- /**
114
- * Internal - used to transition the state machine.
115
- */
116
- _t(to: AdxValidationResultCode, message?: string): void;
117
- /**
118
- * Internal - used to transition the state machine.
119
- */
120
- _fail(schema: AdxSchema, validator: ValidateFunction): void;
121
- }
122
- export declare class AdxValidationError extends Error {
123
- code: AdxValidationResultCode;
124
- messages: string[];
125
- constructor(res: AdxValidationResult);
126
- }
1
+ export * from './types';
2
+ export * from './lexicons';
package/dist/index.js CHANGED
@@ -1,8 +1,13 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __commonJS = (cb, mod2) => function __require() {
9
+ return mod2 || (0, cb[__getOwnPropNames(cb)[0]])((mod2 = { exports: {} }).exports, mod2), mod2.exports;
10
+ };
6
11
  var __export = (target, all) => {
7
12
  for (var name in all)
8
13
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -15,8 +20,61 @@ var __copyProps = (to, from, except, desc) => {
15
20
  }
16
21
  return to;
17
22
  };
23
+ var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__getProtoOf(mod2)) : {}, __copyProps(
24
+ isNodeMode || !mod2 || !mod2.__esModule ? __defProp(target, "default", { value: mod2, enumerable: true }) : target,
25
+ mod2
26
+ ));
18
27
  var __toCommonJS = (mod2) => __copyProps(__defProp({}, "__esModule", { value: true }), mod2);
19
28
 
29
+ // ../../node_modules/iso-datestring-validator/dist/index.js
30
+ var require_dist = __commonJS({
31
+ "../../node_modules/iso-datestring-validator/dist/index.js"(exports) {
32
+ (() => {
33
+ "use strict";
34
+ var e = { d: (t2, r2) => {
35
+ for (var n2 in r2)
36
+ e.o(r2, n2) && !e.o(t2, n2) && Object.defineProperty(t2, n2, { enumerable: true, get: r2[n2] });
37
+ }, o: (e2, t2) => Object.prototype.hasOwnProperty.call(e2, t2), r: (e2) => {
38
+ "undefined" != typeof Symbol && Symbol.toStringTag && Object.defineProperty(e2, Symbol.toStringTag, { value: "Module" }), Object.defineProperty(e2, "__esModule", { value: true });
39
+ } }, t = {};
40
+ function r(e2, t2) {
41
+ return void 0 === t2 && (t2 = "-"), new RegExp("^(?!0{4}" + t2 + "0{2}" + t2 + "0{2})((?=[0-9]{4}" + t2 + "(((0[^2])|1[0-2])|02(?=" + t2 + "(([0-1][0-9])|2[0-8])))" + t2 + "[0-9]{2})|(?=((([13579][26])|([2468][048])|(0[48]))0{2})|([0-9]{2}((((0|[2468])[48])|[2468][048])|([13579][26])))" + t2 + "02" + t2 + "29))([0-9]{4})" + t2 + "(?!((0[469])|11)" + t2 + "31)((0[1,3-9]|1[0-2])|(02(?!" + t2 + "3)))" + t2 + "(0[1-9]|[1-2][0-9]|3[0-1])$").test(e2);
42
+ }
43
+ function n(e2) {
44
+ var t2 = /\D/.exec(e2);
45
+ return t2 ? t2[0] : "";
46
+ }
47
+ function i(e2, t2, r2) {
48
+ void 0 === t2 && (t2 = ":"), void 0 === r2 && (r2 = false);
49
+ var i2 = new RegExp("^([0-1]|2(?=([0-3])|4" + t2 + "00))[0-9]" + t2 + "[0-5][0-9](" + t2 + "([0-5]|6(?=0))[0-9])?(.[0-9]{1,9})?$");
50
+ if (!r2 || !/[Z+\-]/.test(e2))
51
+ return i2.test(e2);
52
+ if (/Z$/.test(e2))
53
+ return i2.test(e2.replace("Z", ""));
54
+ var o2 = e2.includes("+"), a2 = e2.split(/[+-]/), u2 = a2[0], d2 = a2[1];
55
+ return i2.test(u2) && function(e3, t3, r3) {
56
+ return void 0 === r3 && (r3 = ":"), new RegExp(t3 ? "^(0(?!(2" + r3 + "4)|0" + r3 + "3)|1(?=([0-1]|2(?=" + r3 + "[04])|[34](?=" + r3 + "0))))([03469](?=" + r3 + "[03])|[17](?=" + r3 + "0)|2(?=" + r3 + "[04])|5(?=" + r3 + "[034])|8(?=" + r3 + "[04]))" + r3 + "([03](?=0)|4(?=5))[05]$" : "^(0(?=[^0])|1(?=[0-2]))([39](?=" + r3 + "[03])|[0-24-8](?=" + r3 + "00))" + r3 + "[03]0$").test(e3);
57
+ }(d2, o2, n(d2));
58
+ }
59
+ function o(e2) {
60
+ var t2 = e2.split("T"), o2 = t2[0], a2 = t2[1], u2 = r(o2, n(o2));
61
+ if (!a2)
62
+ return false;
63
+ var d2, s = (d2 = a2.match(/([^Z+\-\d])(?=\d+\1)/), Array.isArray(d2) ? d2[0] : "");
64
+ return u2 && i(a2, s, true);
65
+ }
66
+ function a(e2, t2) {
67
+ return void 0 === t2 && (t2 = "-"), new RegExp("^[0-9]{4}" + t2 + "(0(?=[^0])|1(?=[0-2]))[0-9]$").test(e2);
68
+ }
69
+ e.r(t), e.d(t, { isValidDate: () => r, isValidISODateString: () => o, isValidTime: () => i, isValidYearMonth: () => a });
70
+ var u = exports;
71
+ for (var d in t)
72
+ u[d] = t[d];
73
+ t.__esModule && Object.defineProperty(u, "__esModule", { value: true });
74
+ })();
75
+ }
76
+ });
77
+
20
78
  // src/index.ts
21
79
  var src_exports = {};
22
80
  __export(src_exports, {
@@ -3242,6 +3300,7 @@ var LexiconDefNotFoundError = class extends Error {
3242
3300
  };
3243
3301
 
3244
3302
  // src/validators/primitives.ts
3303
+ var import_iso_datestring_validator = __toESM(require_dist());
3245
3304
  function validate(lexicons, path, def, value) {
3246
3305
  switch (def.type) {
3247
3306
  case "boolean":
@@ -3429,8 +3488,7 @@ function datetime(lexicons, path, def, value) {
3429
3488
  }
3430
3489
  {
3431
3490
  try {
3432
- const date = new Date(Date.parse(value));
3433
- if (value !== date.toISOString()) {
3491
+ if (typeof value !== "string" || !(0, import_iso_datestring_validator.isValidISODateString)(value)) {
3434
3492
  throw new ValidationError(
3435
3493
  `${path} must be an iso8601 formatted datetime`
3436
3494
  );