@atproto/lexicon 0.3.3 → 0.4.1-rc.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 (62) hide show
  1. package/CHANGELOG.md +42 -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 +54 -2
  11. package/dist/lexicons.d.ts.map +1 -0
  12. package/dist/lexicons.js +242 -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 +4864 -4103
  19. package/dist/types.d.ts.map +1 -0
  20. package/dist/types.js +333 -0
  21. package/dist/types.js.map +1 -0
  22. package/dist/util.d.ts +3 -4
  23. package/dist/util.d.ts.map +1 -0
  24. package/dist/util.js +65 -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 +49 -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 +3 -1
  35. package/dist/validators/complex.d.ts.map +1 -0
  36. package/dist/validators/complex.js +196 -0
  37. package/dist/validators/complex.js.map +1 -0
  38. package/dist/validators/formats.d.ts +3 -0
  39. package/dist/validators/formats.d.ts.map +1 -0
  40. package/dist/validators/formats.js +151 -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 +293 -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 +10 -9
  52. package/src/lexicons.ts +18 -3
  53. package/src/types.ts +2 -0
  54. package/src/util.ts +2 -95
  55. package/src/validation.ts +18 -5
  56. package/src/validators/complex.ts +102 -11
  57. package/src/validators/formats.ts +28 -0
  58. package/src/validators/primitives.ts +4 -0
  59. package/tsconfig.build.json +6 -2
  60. package/tsconfig.json +3 -10
  61. package/tsconfig.tests.json +7 -0
  62. package/build.js +0 -14
@@ -0,0 +1 @@
1
+ {"version":3,"file":"primitives.js","sourceRoot":"","sources":["../../src/validators/primitives.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAA0D;AAC1D,0CAAsC;AAEtC,mDAAoC;AACpC,oCAQiB;AAEjB,SAAgB,QAAQ,CACtB,QAAkB,EAClB,IAAY,EACZ,GAAgB,EAChB,KAAc;IAEd,QAAQ,GAAG,CAAC,IAAI,EAAE,CAAC;QACjB,KAAK,SAAS;YACZ,OAAO,OAAO,CAAC,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAA;QAC5C,KAAK,SAAS;YACZ,OAAO,OAAO,CAAC,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAA;QAC5C,KAAK,QAAQ;YACX,OAAO,MAAM,CAAC,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAA;QAC3C,KAAK,OAAO;YACV,OAAO,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAA;QAC1C,KAAK,UAAU;YACb,OAAO,OAAO,CAAC,QAA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pcParameters, ValidationResult } from '../types';
3
3
  export declare function params(lexicons: Lexicons, path: string, def: LexXrpcParameters, val: unknown): ValidationResult;
4
+ //# sourceMappingURL=xrpc.d.ts.map
@@ -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,GAAsB,EACtB,GAAY;IAEZ,OAAO;IACP,MAAM,KAAK,GAAG,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAA;IAEvD,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,QAAQ,IAA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BAC5B,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.1-rc.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
- "zod": "^3.21.4",
21
- "@atproto/common-web": "^0.2.4",
22
- "@atproto/syntax": "^0.2.1"
21
+ "zod": "^3.23.8",
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
  }
package/src/lexicons.ts CHANGED
@@ -22,18 +22,33 @@ import * as ComplexValidators from './validators/complex'
22
22
  /**
23
23
  * A collection of compiled lexicons.
24
24
  */
25
- export class Lexicons {
25
+ export class Lexicons implements Iterable<LexiconDoc> {
26
26
  docs: Map<string, LexiconDoc> = new Map()
27
27
  defs: Map<string, LexUserType> = new Map()
28
28
 
29
- constructor(docs?: LexiconDoc[]) {
30
- if (docs?.length) {
29
+ constructor(docs?: Iterable<LexiconDoc>) {
30
+ if (docs) {
31
31
  for (const doc of docs) {
32
32
  this.add(doc)
33
33
  }
34
34
  }
35
35
  }
36
36
 
37
+ /**
38
+ * @example clone a lexicon:
39
+ * ```ts
40
+ * const clone = new Lexicons(originalLexicon)
41
+ * ```
42
+ *
43
+ * @example get docs array:
44
+ * ```ts
45
+ * const docs = Array.from(lexicons)
46
+ * ```
47
+ */
48
+ [Symbol.iterator](): Iterator<LexiconDoc> {
49
+ return this.docs.values()
50
+ }
51
+
37
52
  /**
38
53
  * Add a lexicon doc.
39
54
  */
package/src/types.ts CHANGED
@@ -38,6 +38,8 @@ export const lexStringFormat = z.enum([
38
38
  'nsid',
39
39
  'cid',
40
40
  'language',
41
+ 'tid',
42
+ 'record-key',
41
43
  ])
42
44
  export type LexStringFormat = z.infer<typeof lexStringFormat>
43
45
 
package/src/util.ts CHANGED
@@ -1,13 +1,6 @@
1
- import { Lexicons } from './lexicons'
2
- import * as ComplexValidators from './validators/complex'
3
- import {
4
- LexUserType,
5
- LexRefVariant,
6
- ValidationError,
7
- ValidationResult,
8
- isDiscriminatedObject,
9
- } from './types'
10
1
  import { z } from 'zod'
2
+ import { Lexicons } from './lexicons'
3
+ import { LexRefVariant, LexUserType } from './types'
11
4
 
12
5
  export function toLexUri(str: string, baseUri?: string): string {
13
6
  if (str.split('#').length > 2) {
@@ -26,77 +19,6 @@ export function toLexUri(str: string, baseUri?: string): string {
26
19
  return `lex:${str}`
27
20
  }
28
21
 
29
- export function validateOneOf(
30
- lexicons: Lexicons,
31
- path: string,
32
- def: LexRefVariant | LexUserType,
33
- value: unknown,
34
- mustBeObj = false, // this is the only type constraint we need currently (used by xrpc body schema validators)
35
- ): ValidationResult {
36
- let error
37
-
38
- let concreteDefs
39
- if (def.type === 'union') {
40
- if (!isDiscriminatedObject(value)) {
41
- return {
42
- success: false,
43
- error: new ValidationError(
44
- `${path} must be an object which includes the "$type" property`,
45
- ),
46
- }
47
- }
48
- if (!refsContainType(def.refs, value.$type)) {
49
- if (def.closed) {
50
- return {
51
- success: false,
52
- error: new ValidationError(
53
- `${path} $type must be one of ${def.refs.join(', ')}`,
54
- ),
55
- }
56
- }
57
- return { success: true, value }
58
- } else {
59
- concreteDefs = toConcreteTypes(lexicons, {
60
- type: 'ref',
61
- ref: value.$type,
62
- })
63
- }
64
- } else {
65
- concreteDefs = toConcreteTypes(lexicons, def)
66
- }
67
-
68
- for (const concreteDef of concreteDefs) {
69
- const result = mustBeObj
70
- ? ComplexValidators.object(lexicons, path, concreteDef, value)
71
- : ComplexValidators.validate(lexicons, path, concreteDef, value)
72
- if (result.success) {
73
- return result
74
- }
75
- error ??= result.error
76
- }
77
- if (concreteDefs.length > 1) {
78
- return {
79
- success: false,
80
- error: new ValidationError(
81
- `${path} did not match any of the expected definitions`,
82
- ),
83
- }
84
- }
85
- return { success: false, error }
86
- }
87
-
88
- export function assertValidOneOf(
89
- lexicons: Lexicons,
90
- path: string,
91
- def: LexRefVariant | LexUserType,
92
- value: unknown,
93
- mustBeObj = false,
94
- ) {
95
- const res = validateOneOf(lexicons, path, def, value, mustBeObj)
96
- if (!res.success) throw res.error
97
- return res.value
98
- }
99
-
100
22
  export function toConcreteTypes(
101
23
  lexicons: Lexicons,
102
24
  def: LexRefVariant | LexUserType,
@@ -149,18 +71,3 @@ export function requiredPropertiesRefinement<
149
71
  }
150
72
  }
151
73
  }
152
-
153
- // to avoid bugs like #0189 this needs to handle both
154
- // explicit and implicit #main
155
- const refsContainType = (refs: string[], type: string) => {
156
- const lexUri = toLexUri(type)
157
- if (refs.includes(lexUri)) {
158
- return true
159
- }
160
-
161
- if (lexUri.endsWith('#main')) {
162
- return refs.includes(lexUri.replace('#main', ''))
163
- } else {
164
- return refs.includes(lexUri + '#main')
165
- }
166
- }
package/src/validation.ts CHANGED
@@ -1,21 +1,22 @@
1
1
  import { Lexicons } from './lexicons'
2
2
  import {
3
3
  LexRecord,
4
+ LexRefVariant,
5
+ LexUserType,
4
6
  LexXrpcProcedure,
5
7
  LexXrpcQuery,
6
8
  LexXrpcSubscription,
7
9
  } from './types'
8
- import { assertValidOneOf } from './util'
9
10
 
10
- import * as ComplexValidators from './validators/complex'
11
- import * as XrpcValidators from './validators/xrpc'
11
+ import { object, validateOneOf } from './validators/complex'
12
+ import { params } from './validators/xrpc'
12
13
 
13
14
  export function assertValidRecord(
14
15
  lexicons: Lexicons,
15
16
  def: LexRecord,
16
17
  value: unknown,
17
18
  ) {
18
- const res = ComplexValidators.object(lexicons, 'Record', def.record, value)
19
+ const res = object(lexicons, 'Record', def.record, value)
19
20
  if (!res.success) throw res.error
20
21
  return res.value
21
22
  }
@@ -26,7 +27,7 @@ export function assertValidXrpcParams(
26
27
  value: unknown,
27
28
  ) {
28
29
  if (def.parameters) {
29
- const res = XrpcValidators.params(lexicons, 'Params', def.parameters, value)
30
+ const res = params(lexicons, 'Params', def.parameters, value)
30
31
  if (!res.success) throw res.error
31
32
  return res.value
32
33
  }
@@ -70,3 +71,15 @@ export function assertValidXrpcMessage(
70
71
  )
71
72
  }
72
73
  }
74
+
75
+ function assertValidOneOf(
76
+ lexicons: Lexicons,
77
+ path: string,
78
+ def: LexRefVariant | LexUserType,
79
+ value: unknown,
80
+ mustBeObj = false,
81
+ ) {
82
+ const res = validateOneOf(lexicons, path, def, value, mustBeObj)
83
+ if (!res.success) throw res.error
84
+ return res.value
85
+ }
@@ -2,14 +2,16 @@ import { Lexicons } from '../lexicons'
2
2
  import {
3
3
  LexArray,
4
4
  LexObject,
5
+ LexRefVariant,
5
6
  LexUserType,
6
- ValidationResult,
7
7
  ValidationError,
8
+ ValidationResult,
9
+ isDiscriminatedObject,
8
10
  } from '../types'
9
- import { validateOneOf } from '../util'
11
+ import { toConcreteTypes, toLexUri } from '../util'
10
12
 
11
- import * as Primitives from './primitives'
12
- import * as Blob from './blob'
13
+ import { blob } from './blob'
14
+ import { boolean, integer, string, bytes, cidLink, unknown } from './primitives'
13
15
 
14
16
  export function validate(
15
17
  lexicons: Lexicons,
@@ -19,23 +21,23 @@ export function validate(
19
21
  ): ValidationResult {
20
22
  switch (def.type) {
21
23
  case 'boolean':
22
- return Primitives.boolean(lexicons, path, def, value)
24
+ return boolean(lexicons, path, def, value)
23
25
  case 'integer':
24
- return Primitives.integer(lexicons, path, def, value)
26
+ return integer(lexicons, path, def, value)
25
27
  case 'string':
26
- return Primitives.string(lexicons, path, def, value)
28
+ return string(lexicons, path, def, value)
27
29
  case 'bytes':
28
- return Primitives.bytes(lexicons, path, def, value)
30
+ return bytes(lexicons, path, def, value)
29
31
  case 'cid-link':
30
- return Primitives.cidLink(lexicons, path, def, value)
32
+ return cidLink(lexicons, path, def, value)
31
33
  case 'unknown':
32
- return Primitives.unknown(lexicons, path, def, value)
34
+ return unknown(lexicons, path, def, value)
33
35
  case 'object':
34
36
  return object(lexicons, path, def, value)
35
37
  case 'array':
36
38
  return array(lexicons, path, def, value)
37
39
  case 'blob':
38
- return Blob.blob(lexicons, path, def, value)
40
+ return blob(lexicons, path, def, value)
39
41
  default:
40
42
  return {
41
43
  success: false,
@@ -123,6 +125,21 @@ export function object(
123
125
  continue
124
126
  }
125
127
  const propDef = def.properties[key]
128
+ if (typeof value[key] === 'undefined' && !requiredProps.has(key)) {
129
+ // Fast path for non-required undefined props.
130
+ if (
131
+ propDef.type === 'integer' ||
132
+ propDef.type === 'boolean' ||
133
+ propDef.type === 'string'
134
+ ) {
135
+ if (typeof propDef.default === 'undefined') {
136
+ continue
137
+ }
138
+ } else {
139
+ // Other types have no defaults.
140
+ continue
141
+ }
142
+ }
126
143
  const propPath = `${path}/${key}`
127
144
  const validated = validateOneOf(lexicons, propPath, propDef, value[key])
128
145
  const propValue = validated.success ? validated.value : value[key]
@@ -149,3 +166,77 @@ export function object(
149
166
 
150
167
  return { success: true, value: resultValue }
151
168
  }
169
+
170
+ export function validateOneOf(
171
+ lexicons: Lexicons,
172
+ path: string,
173
+ def: LexRefVariant | LexUserType,
174
+ value: unknown,
175
+ mustBeObj = false, // this is the only type constraint we need currently (used by xrpc body schema validators)
176
+ ): ValidationResult {
177
+ let error
178
+
179
+ let concreteDefs
180
+ if (def.type === 'union') {
181
+ if (!isDiscriminatedObject(value)) {
182
+ return {
183
+ success: false,
184
+ error: new ValidationError(
185
+ `${path} must be an object which includes the "$type" property`,
186
+ ),
187
+ }
188
+ }
189
+ if (!refsContainType(def.refs, value.$type)) {
190
+ if (def.closed) {
191
+ return {
192
+ success: false,
193
+ error: new ValidationError(
194
+ `${path} $type must be one of ${def.refs.join(', ')}`,
195
+ ),
196
+ }
197
+ }
198
+ return { success: true, value }
199
+ } else {
200
+ concreteDefs = toConcreteTypes(lexicons, {
201
+ type: 'ref',
202
+ ref: value.$type,
203
+ })
204
+ }
205
+ } else {
206
+ concreteDefs = toConcreteTypes(lexicons, def)
207
+ }
208
+
209
+ for (const concreteDef of concreteDefs) {
210
+ const result = mustBeObj
211
+ ? object(lexicons, path, concreteDef, value)
212
+ : validate(lexicons, path, concreteDef, value)
213
+ if (result.success) {
214
+ return result
215
+ }
216
+ error ??= result.error
217
+ }
218
+ if (concreteDefs.length > 1) {
219
+ return {
220
+ success: false,
221
+ error: new ValidationError(
222
+ `${path} did not match any of the expected definitions`,
223
+ ),
224
+ }
225
+ }
226
+ return { success: false, error }
227
+ }
228
+
229
+ // to avoid bugs like #0189 this needs to handle both
230
+ // explicit and implicit #main
231
+ const refsContainType = (refs: string[], type: string) => {
232
+ const lexUri = toLexUri(type)
233
+ if (refs.includes(lexUri)) {
234
+ return true
235
+ }
236
+
237
+ if (lexUri.endsWith('#main')) {
238
+ return refs.includes(lexUri.replace('#main', ''))
239
+ } else {
240
+ return refs.includes(lexUri + '#main')
241
+ }
242
+ }
@@ -6,6 +6,8 @@ import {
6
6
  ensureValidHandle,
7
7
  ensureValidNsid,
8
8
  ensureValidAtUri,
9
+ ensureValidTid,
10
+ ensureValidRecordKey,
9
11
  } from '@atproto/syntax'
10
12
  import { validateLanguage } from '@atproto/common-web'
11
13
 
@@ -122,3 +124,29 @@ export function language(path: string, value: string): ValidationResult {
122
124
  ),
123
125
  }
124
126
  }
127
+
128
+ export function tid(path: string, value: string): ValidationResult {
129
+ try {
130
+ ensureValidTid(value)
131
+ } catch {
132
+ return {
133
+ success: false,
134
+ error: new ValidationError(
135
+ `${path} must be a valid TID (timestamp identifier)`,
136
+ ),
137
+ }
138
+ }
139
+ return { success: true, value }
140
+ }
141
+
142
+ export function recordKey(path: string, value: string): ValidationResult {
143
+ try {
144
+ ensureValidRecordKey(value)
145
+ } catch {
146
+ return {
147
+ success: false,
148
+ error: new ValidationError(`${path} must be a valid Record Key`),
149
+ }
150
+ }
151
+ return { success: true, value }
152
+ }
@@ -265,6 +265,10 @@ export function string(
265
265
  return formats.cid(path, value)
266
266
  case 'language':
267
267
  return formats.language(path, value)
268
+ case 'tid':
269
+ return formats.tid(path, value)
270
+ case 'record-key':
271
+ return formats.recordKey(path, value)
268
272
  }
269
273
  }
270
274
 
@@ -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
- })