@atproto/lexicon 0.3.1 → 0.3.3-next.0

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.
Files changed (57) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/LICENSE.txt +1 -1
  3. package/dist/blob-refs.d.ts +8 -7
  4. package/dist/blob-refs.d.ts.map +1 -0
  5. package/dist/blob-refs.js +82 -0
  6. package/dist/blob-refs.js.map +1 -0
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.d.ts.map +1 -0
  9. package/dist/index.js +20 -15097
  10. package/dist/index.js.map +1 -7
  11. package/dist/lexicons.d.ts +43 -1
  12. package/dist/lexicons.d.ts.map +1 -0
  13. package/dist/lexicons.js +228 -0
  14. package/dist/lexicons.js.map +1 -0
  15. package/dist/serialize.d.ts +3 -2
  16. package/dist/serialize.d.ts.map +1 -0
  17. package/dist/serialize.js +80 -0
  18. package/dist/serialize.js.map +1 -0
  19. package/dist/types.d.ts +430 -429
  20. package/dist/types.d.ts.map +1 -0
  21. package/dist/types.js +331 -0
  22. package/dist/types.js.map +1 -0
  23. package/dist/util.d.ts +1 -0
  24. package/dist/util.d.ts.map +1 -0
  25. package/dist/util.js +158 -0
  26. package/dist/util.js.map +1 -0
  27. package/dist/validation.d.ts +1 -0
  28. package/dist/validation.d.ts.map +1 -0
  29. package/dist/validation.js +67 -0
  30. package/dist/validation.js.map +1 -0
  31. package/dist/validators/blob.d.ts +1 -0
  32. package/dist/validators/blob.d.ts.map +1 -0
  33. package/dist/validators/blob.js +17 -0
  34. package/dist/validators/blob.js.map +1 -0
  35. package/dist/validators/complex.d.ts +1 -0
  36. package/dist/validators/complex.d.ts.map +1 -0
  37. package/dist/validators/complex.js +144 -0
  38. package/dist/validators/complex.js.map +1 -0
  39. package/dist/validators/formats.d.ts +1 -0
  40. package/dist/validators/formats.d.ts.map +1 -0
  41. package/dist/validators/formats.js +125 -0
  42. package/dist/validators/formats.js.map +1 -0
  43. package/dist/validators/primitives.d.ts +1 -0
  44. package/dist/validators/primitives.d.ts.map +1 -0
  45. package/dist/validators/primitives.js +289 -0
  46. package/dist/validators/primitives.js.map +1 -0
  47. package/dist/validators/xrpc.d.ts +1 -0
  48. package/dist/validators/xrpc.d.ts.map +1 -0
  49. package/dist/validators/xrpc.js +67 -0
  50. package/dist/validators/xrpc.js.map +1 -0
  51. package/jest.config.js +4 -3
  52. package/package.json +9 -8
  53. package/src/lexicons.ts +13 -17
  54. package/tsconfig.build.json +6 -2
  55. package/tsconfig.json +3 -10
  56. package/tsconfig.tests.json +7 -0
  57. package/build.js +0 -14
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xrpc.d.ts","sourceRoot":"","sources":["../../src/validators/xrpc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAmB,MAAM,UAAU,CAAA;AAK/E,wBAAgB,MAAM,CACpB,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,iBAAiB,EACtB,GAAG,EAAE,OAAO,GACX,gBAAgB,CAsClB"}
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.params = void 0;
27
+ const types_1 = require("../types");
28
+ const PrimitiveValidators = __importStar(require("./primitives"));
29
+ const complex_1 = require("./complex");
30
+ function params(lexicons, path, def, val) {
31
+ // type
32
+ const value = val && typeof val === 'object' ? val : {};
33
+ const requiredProps = new Set(def.required ?? []);
34
+ // properties
35
+ let resultValue = value;
36
+ if (typeof def.properties === 'object') {
37
+ for (const key in def.properties) {
38
+ const propDef = def.properties[key];
39
+ const validated = propDef.type === 'array'
40
+ ? (0, complex_1.array)(lexicons, key, propDef, value[key])
41
+ : PrimitiveValidators.validate(lexicons, key, propDef, value[key]);
42
+ const propValue = validated.success ? validated.value : value[key];
43
+ const propIsUndefined = typeof propValue === 'undefined';
44
+ // Return error for bad validation, giving required rule precedence
45
+ if (propIsUndefined && requiredProps.has(key)) {
46
+ return {
47
+ success: false,
48
+ error: new types_1.ValidationError(`${path} must have the property "${key}"`),
49
+ };
50
+ }
51
+ else if (!propIsUndefined && !validated.success) {
52
+ return validated;
53
+ }
54
+ // Adjust value based on e.g. applied defaults, cloning shallowly if there was a changed value
55
+ if (propValue !== value[key]) {
56
+ if (resultValue === value) {
57
+ // Lazy shallow clone
58
+ resultValue = { ...value };
59
+ }
60
+ resultValue[key] = propValue;
61
+ }
62
+ }
63
+ }
64
+ return { success: true, value: resultValue };
65
+ }
66
+ exports.params = params;
67
+ //# sourceMappingURL=xrpc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xrpc.js","sourceRoot":"","sources":["../../src/validators/xrpc.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,oCAA+E;AAE/E,kEAAmD;AACnD,uCAAiC;AA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I,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;gBAClD,OAAO,SAAS,CAAA;YAClB,CAAC;YACD,8FAA8F;YAC9F,IAAI,SAAS,KAAK,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;gBAC7B,IAAI,WAAW,KAAK,KAAK,EAAE,CAAC;oBAC1B,qBAAqB;oBACrB,WAAW,GAAG,EAAE,GAAG,KAAK,EAAE,CAAA;gBAC5B,CAAC;gBACD,WAAW,CAAC,GAAG,CAAC,GAAG,SAAS,CAAA;YAC9B,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE,CAAA;AAC9C,CAAC;AA3CD,wBA2CC"}
package/jest.config.js CHANGED
@@ -1,6 +1,7 @@
1
- const base = require('../../jest.config.base.js')
2
-
1
+ /** @type {import('jest').Config} */
3
2
  module.exports = {
4
- ...base,
5
3
  displayName: 'Lexicon',
4
+ transform: { '^.+\\.(t|j)s$': '@swc/jest' },
5
+ transformIgnorePatterns: [`<rootDir>/node_modules/(?!get-port)`],
6
+ setupFiles: ['<rootDir>/../../jest.setup.ts'],
6
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atproto/lexicon",
3
- "version": "0.3.1",
3
+ "version": "0.3.3-next.0",
4
4
  "license": "MIT",
5
5
  "description": "atproto Lexicon schema language library",
6
6
  "keywords": [
@@ -14,18 +14,19 @@
14
14
  "directory": "packages/lexicon"
15
15
  },
16
16
  "main": "dist/index.js",
17
+ "types": "dist/index.d.ts",
17
18
  "dependencies": {
18
19
  "iso-datestring-validator": "^2.2.2",
19
20
  "multiformats": "^9.9.0",
20
21
  "zod": "^3.21.4",
21
- "@atproto/common-web": "^0.2.3",
22
- "@atproto/syntax": "^0.1.5"
22
+ "@atproto/syntax": "^0.2.1-next.0",
23
+ "@atproto/common-web": "^0.2.4-next.0"
24
+ },
25
+ "devDependencies": {
26
+ "jest": "^28.1.2"
23
27
  },
24
28
  "scripts": {
25
29
  "test": "jest",
26
- "build": "node ./build.js",
27
- "postbuild": "tsc --build tsconfig.build.json",
28
- "update-main-to-dist": "node ../../update-main-to-dist.js packages/lexicon"
29
- },
30
- "types": "dist/index.d.ts"
30
+ "build": "tsc --build tsconfig.build.json"
31
+ }
31
32
  }
package/src/lexicons.ts CHANGED
@@ -1,8 +1,6 @@
1
1
  import {
2
2
  LexiconDoc,
3
3
  LexRecord,
4
- LexXrpcProcedure,
5
- LexXrpcQuery,
6
4
  LexUserType,
7
5
  LexiconDefNotFoundError,
8
6
  InvalidLexiconError,
@@ -10,7 +8,6 @@ import {
10
8
  ValidationError,
11
9
  isObj,
12
10
  hasProp,
13
- LexXrpcSubscription,
14
11
  } from './types'
15
12
  import {
16
13
  assertValidRecord,
@@ -91,7 +88,14 @@ export class Lexicons {
91
88
  /**
92
89
  * Get a def, throw if not found. Throws on not found.
93
90
  */
94
- getDefOrThrow(uri: string, types?: string[]): LexUserType {
91
+ getDefOrThrow<T extends LexUserType['type'] = LexUserType['type']>(
92
+ uri: string,
93
+ types?: readonly T[],
94
+ ): Extract<LexUserType, { type: T }>
95
+ getDefOrThrow(
96
+ uri: string,
97
+ types?: readonly LexUserType['type'][],
98
+ ): LexUserType {
95
99
  const def = this.getDef(uri)
96
100
  if (!def) {
97
101
  throw new LexiconDefNotFoundError(`Lexicon not found: ${uri}`)
@@ -118,7 +122,7 @@ export class Lexicons {
118
122
  } else if (def.type === 'object') {
119
123
  return ComplexValidators.object(this, 'Object', def, value)
120
124
  } else {
121
- // shouldnt happen
125
+ // shouldn't happen
122
126
  throw new InvalidLexiconError('Definition must be a record or object')
123
127
  }
124
128
  }
@@ -154,11 +158,7 @@ export class Lexicons {
154
158
  'procedure',
155
159
  'subscription',
156
160
  ])
157
- return assertValidXrpcParams(
158
- this,
159
- def as LexXrpcProcedure | LexXrpcQuery | LexXrpcSubscription,
160
- value,
161
- )
161
+ return assertValidXrpcParams(this, def, value)
162
162
  }
163
163
 
164
164
  /**
@@ -167,7 +167,7 @@ export class Lexicons {
167
167
  assertValidXrpcInput(lexUri: string, value: unknown) {
168
168
  lexUri = toLexUri(lexUri)
169
169
  const def = this.getDefOrThrow(lexUri, ['procedure'])
170
- return assertValidXrpcInput(this, def as LexXrpcProcedure, value)
170
+ return assertValidXrpcInput(this, def, value)
171
171
  }
172
172
 
173
173
  /**
@@ -176,11 +176,7 @@ export class Lexicons {
176
176
  assertValidXrpcOutput(lexUri: string, value: unknown) {
177
177
  lexUri = toLexUri(lexUri)
178
178
  const def = this.getDefOrThrow(lexUri, ['query', 'procedure'])
179
- return assertValidXrpcOutput(
180
- this,
181
- def as LexXrpcProcedure | LexXrpcQuery,
182
- value,
183
- )
179
+ return assertValidXrpcOutput(this, def, value)
184
180
  }
185
181
 
186
182
  /**
@@ -189,7 +185,7 @@ export class Lexicons {
189
185
  assertValidXrpcMessage<T = unknown>(lexUri: string, value: unknown): T {
190
186
  lexUri = toLexUri(lexUri)
191
187
  const def = this.getDefOrThrow(lexUri, ['subscription'])
192
- return assertValidXrpcMessage(this, def as LexXrpcSubscription, value) as T
188
+ return assertValidXrpcMessage(this, def, value) as T
193
189
  }
194
190
 
195
191
  /**
@@ -1,4 +1,8 @@
1
1
  {
2
- "extends": "./tsconfig.json",
3
- "exclude": ["**/*.spec.ts", "**/*.test.ts"]
2
+ "extends": "../../tsconfig/isomorphic.json",
3
+ "compilerOptions": {
4
+ "rootDir": "./src",
5
+ "outDir": "./dist"
6
+ },
7
+ "include": ["./src"]
4
8
  }
package/tsconfig.json CHANGED
@@ -1,14 +1,7 @@
1
1
  {
2
- "extends": "../../tsconfig.json",
3
- "compilerOptions": {
4
- "rootDir": "./src",
5
- "outDir": "./dist", // Your outDir,
6
- "emitDeclarationOnly": true
7
- },
8
- "include": ["./src"],
2
+ "include": [],
9
3
  "references": [
10
- { "path": "../common/tsconfig.build.json" },
11
- { "path": "../nsid/tsconfig.build.json" },
12
- { "path": "../uri/tsconfig.build.json" }
4
+ { "path": "./tsconfig.build.json" },
5
+ { "path": "./tsconfig.tests.json" }
13
6
  ]
14
7
  }
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../../tsconfig/tests.json",
3
+ "compilerOptions": {
4
+ "rootDir": "."
5
+ },
6
+ "include": ["./tests"]
7
+ }
package/build.js DELETED
@@ -1,14 +0,0 @@
1
- const { nodeExternalsPlugin } = require('esbuild-node-externals')
2
-
3
- const buildShallow =
4
- process.argv.includes('--shallow') || process.env.ATP_BUILD_SHALLOW === 'true'
5
-
6
- require('esbuild').build({
7
- logLevel: 'info',
8
- entryPoints: ['src/index.ts'],
9
- bundle: true,
10
- sourcemap: true,
11
- outdir: 'dist',
12
- platform: 'node',
13
- plugins: buildShallow ? [nodeExternalsPlugin()] : [],
14
- })