@atproto/lexicon 0.3.3 → 0.4.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 (55) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/blob-refs.d.ts +5 -4
  3. package/dist/blob-refs.d.ts.map +1 -0
  4. package/dist/blob-refs.js +82 -0
  5. package/dist/blob-refs.js.map +1 -0
  6. package/dist/index.d.ts +1 -0
  7. package/dist/index.d.ts.map +1 -0
  8. package/dist/index.js +20 -15097
  9. package/dist/index.js.map +1 -7
  10. package/dist/lexicons.d.ts +40 -0
  11. package/dist/lexicons.d.ts.map +1 -0
  12. package/dist/lexicons.js +228 -0
  13. package/dist/lexicons.js.map +1 -0
  14. package/dist/serialize.d.ts +1 -0
  15. package/dist/serialize.d.ts.map +1 -0
  16. package/dist/serialize.js +80 -0
  17. package/dist/serialize.js.map +1 -0
  18. package/dist/types.d.ts +401 -400
  19. package/dist/types.d.ts.map +1 -0
  20. package/dist/types.js +331 -0
  21. package/dist/types.js.map +1 -0
  22. package/dist/util.d.ts +1 -0
  23. package/dist/util.d.ts.map +1 -0
  24. package/dist/util.js +158 -0
  25. package/dist/util.js.map +1 -0
  26. package/dist/validation.d.ts +1 -0
  27. package/dist/validation.d.ts.map +1 -0
  28. package/dist/validation.js +67 -0
  29. package/dist/validation.js.map +1 -0
  30. package/dist/validators/blob.d.ts +1 -0
  31. package/dist/validators/blob.d.ts.map +1 -0
  32. package/dist/validators/blob.js +17 -0
  33. package/dist/validators/blob.js.map +1 -0
  34. package/dist/validators/complex.d.ts +1 -0
  35. package/dist/validators/complex.d.ts.map +1 -0
  36. package/dist/validators/complex.js +144 -0
  37. package/dist/validators/complex.js.map +1 -0
  38. package/dist/validators/formats.d.ts +1 -0
  39. package/dist/validators/formats.d.ts.map +1 -0
  40. package/dist/validators/formats.js +125 -0
  41. package/dist/validators/formats.js.map +1 -0
  42. package/dist/validators/primitives.d.ts +1 -0
  43. package/dist/validators/primitives.d.ts.map +1 -0
  44. package/dist/validators/primitives.js +289 -0
  45. package/dist/validators/primitives.js.map +1 -0
  46. package/dist/validators/xrpc.d.ts +1 -0
  47. package/dist/validators/xrpc.d.ts.map +1 -0
  48. package/dist/validators/xrpc.js +67 -0
  49. package/dist/validators/xrpc.js.map +1 -0
  50. package/jest.config.js +4 -3
  51. package/package.json +9 -8
  52. package/tsconfig.build.json +6 -2
  53. package/tsconfig.json +3 -10
  54. package/tsconfig.tests.json +7 -0
  55. 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;AAEjC,SAAgB,MAAM,CACpB,QAAkB,EAClB,IAAY,EACZ,GA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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.3",
3
+ "version": "0.4.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.4",
22
- "@atproto/syntax": "^0.2.1"
22
+ "@atproto/common-web": "^0.3.0",
23
+ "@atproto/syntax": "^0.3.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
  }
@@ -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
- })