@atproto/lex-builder 0.1.4 → 0.1.5

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 (43) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/filtered-indexer.d.ts +2 -2
  3. package/dist/filtered-indexer.d.ts.map +1 -1
  4. package/dist/filtered-indexer.js.map +1 -1
  5. package/dist/formatter.d.ts +1 -1
  6. package/dist/formatter.d.ts.map +1 -1
  7. package/dist/formatter.js +1 -1
  8. package/dist/formatter.js.map +1 -1
  9. package/dist/index.d.ts +1 -1
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +1 -1
  12. package/dist/index.js.map +1 -1
  13. package/dist/lex-builder.d.ts +4 -4
  14. package/dist/lex-builder.d.ts.map +1 -1
  15. package/dist/lex-builder.js +53 -2
  16. package/dist/lex-builder.js.map +1 -1
  17. package/dist/lex-def-builder.d.ts +2 -2
  18. package/dist/lex-def-builder.d.ts.map +1 -1
  19. package/dist/lex-def-builder.js +1 -1
  20. package/dist/lex-def-builder.js.map +1 -1
  21. package/dist/lexicon-directory-indexer.d.ts.map +1 -1
  22. package/dist/lexicon-directory-indexer.js.map +1 -1
  23. package/dist/ref-resolver.d.ts +1 -1
  24. package/dist/ref-resolver.d.ts.map +1 -1
  25. package/dist/ref-resolver.js +1 -0
  26. package/dist/ref-resolver.js.map +1 -1
  27. package/package.json +6 -10
  28. package/src/filter.ts +0 -96
  29. package/src/filtered-indexer.test.ts +0 -84
  30. package/src/filtered-indexer.ts +0 -60
  31. package/src/formatter.ts +0 -83
  32. package/src/index.ts +0 -56
  33. package/src/lex-builder.ts +0 -299
  34. package/src/lex-def-builder.ts +0 -1035
  35. package/src/lexicon-directory-indexer.ts +0 -65
  36. package/src/polyfill.ts +0 -7
  37. package/src/ref-resolver.test.ts +0 -75
  38. package/src/ref-resolver.ts +0 -437
  39. package/src/ts-lang.ts +0 -197
  40. package/src/util.ts +0 -72
  41. package/tsconfig.build.json +0 -13
  42. package/tsconfig.json +0 -7
  43. package/tsconfig.tests.json +0 -8
package/src/ts-lang.ts DELETED
@@ -1,197 +0,0 @@
1
- /**
2
- * Set of JavaScript reserved keywords and future reserved words.
3
- *
4
- * These identifiers cannot be used as variable or type names in generated code.
5
- *
6
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar}
7
- */
8
- const JS_KEYWORDS = new Set([
9
- 'abstract',
10
- 'arguments',
11
- 'as',
12
- 'async',
13
- 'await',
14
- 'boolean',
15
- 'break',
16
- 'byte',
17
- 'case',
18
- 'catch',
19
- 'char',
20
- 'class',
21
- 'const',
22
- 'continue',
23
- 'debugger',
24
- 'default',
25
- 'delete',
26
- 'do',
27
- 'double',
28
- 'else',
29
- 'enum',
30
- 'eval',
31
- 'export',
32
- 'extends',
33
- 'false',
34
- 'final',
35
- 'finally',
36
- 'float',
37
- 'for',
38
- 'from',
39
- 'function',
40
- 'get',
41
- 'goto',
42
- 'if',
43
- 'implements',
44
- 'import',
45
- 'in',
46
- 'instanceof',
47
- 'int',
48
- 'interface',
49
- 'let',
50
- 'long',
51
- 'native',
52
- 'new',
53
- 'null',
54
- 'of',
55
- 'package',
56
- 'private',
57
- 'protected',
58
- 'public',
59
- 'return',
60
- 'set',
61
- 'short',
62
- 'static',
63
- 'super',
64
- 'switch',
65
- 'synchronized',
66
- 'this',
67
- 'throw',
68
- 'throws',
69
- 'transient',
70
- 'true',
71
- 'try',
72
- 'typeof',
73
- 'undefined',
74
- 'using',
75
- 'var',
76
- 'void',
77
- 'volatile',
78
- 'while',
79
- 'with',
80
- 'yield',
81
- ])
82
-
83
- /**
84
- * Checks if a word is a JavaScript reserved keyword.
85
- *
86
- * @param word - The identifier to check
87
- * @returns `true` if the word is a reserved keyword
88
- */
89
- export function isJsKeyword(word: string) {
90
- return JS_KEYWORDS.has(word)
91
- }
92
-
93
- // Only important to list var/type names that are likely to be used in the
94
- // generated code files.
95
- const GLOBAL_IDENTIFIERS = new Set([
96
- // import { l } from "@atproto/lex-schema"
97
- 'l',
98
- // JS Globals
99
- 'self',
100
- 'globalThis',
101
- // ESM
102
- 'import',
103
- // CommonJS
104
- '__dirname',
105
- '__filename',
106
- 'require',
107
- 'module',
108
- 'exports',
109
- // TS Primitives
110
- 'any',
111
- 'bigint',
112
- 'boolean',
113
- 'declare',
114
- 'never',
115
- 'null',
116
- 'number',
117
- 'object',
118
- 'string',
119
- 'symbol',
120
- 'undefined',
121
- 'unknown',
122
- 'void',
123
- // TS Utility types
124
- 'Record',
125
- 'Partial',
126
- 'Readonly',
127
- 'Pick',
128
- 'Omit',
129
- 'Exclude',
130
- 'Extract',
131
- 'InstanceType',
132
- 'ReturnType',
133
- 'Required',
134
- 'ThisType',
135
- 'Uppercase',
136
- 'Lowercase',
137
- 'Capitalize',
138
- 'Uncapitalize',
139
- ])
140
-
141
- /**
142
- * Checks if a word is a global identifier that should be avoided.
143
- *
144
- * This includes JavaScript globals, TypeScript built-in types, and
145
- * identifiers commonly used in the generated code.
146
- *
147
- * @param word - The identifier to check
148
- * @returns `true` if the word is a global identifier
149
- */
150
- export function isGlobalIdentifier(word: string) {
151
- return GLOBAL_IDENTIFIERS.has(word)
152
- }
153
-
154
- /**
155
- * Checks if a name is safe to use as a local identifier.
156
- *
157
- * A safe local identifier is a valid JavaScript identifier that does not
158
- * conflict with global identifiers.
159
- *
160
- * @param name - The identifier to check
161
- * @returns `true` if the name is safe to use locally
162
- */
163
- export function isSafeLocalIdentifier(name: string) {
164
- return !isGlobalIdentifier(name) && isValidJsIdentifier(name)
165
- }
166
-
167
- /**
168
- * Checks if a name is a valid JavaScript identifier.
169
- *
170
- * Valid identifiers start with a letter, underscore, or dollar sign,
171
- * followed by any combination of letters, digits, underscores, or dollar
172
- * signs. Reserved keywords are not valid identifiers.
173
- *
174
- * @param name - The string to check
175
- * @returns `true` if the name is a valid identifier
176
- */
177
- export function isValidJsIdentifier(name: string) {
178
- return (
179
- name.length > 0 &&
180
- !isJsKeyword(name) &&
181
- /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name)
182
- )
183
- }
184
-
185
- /**
186
- * Converts a name to a valid namespace export identifier.
187
- *
188
- * If the name is a valid JavaScript identifier, it is returned as-is.
189
- * Otherwise, it is returned as a quoted string for use in export statements
190
- * like `export { foo as "unsafe-name" }`.
191
- *
192
- * @param name - The export name
193
- * @returns The name as a valid export identifier
194
- */
195
- export function asNamespaceExport(name: string) {
196
- return isValidJsIdentifier(name) ? name : JSON.stringify(name)
197
- }
package/src/util.ts DELETED
@@ -1,72 +0,0 @@
1
- import { relative } from 'node:path'
2
-
3
- export function memoize<T extends (arg: string) => NonNullable<unknown> | null>(
4
- fn: T,
5
- ): T {
6
- const cache = new Map<string, NonNullable<unknown> | null>()
7
- return ((arg: string) => {
8
- const cached = cache.get(arg)
9
- if (cached !== undefined) return cached
10
- const result = fn(arg)
11
- cache.set(arg, result)
12
- return result
13
- }) as T
14
- }
15
-
16
- export function startsWithLower(str: string) {
17
- const code = str.charCodeAt(0)
18
- return code >= 97 && code <= 122 // 'a' to 'z'
19
- }
20
-
21
- export function ucFirst(str: string) {
22
- return str.charAt(0).toUpperCase() + str.slice(1)
23
- }
24
-
25
- export function lcFirst(str: string) {
26
- return str.charAt(0).toLowerCase() + str.slice(1)
27
- }
28
-
29
- export function toPascalCase(str: string): string {
30
- return extractWords(str).map(toLowerCase).map(ucFirst).join('')
31
- }
32
-
33
- export function toCamelCase(str: string): string {
34
- return lcFirst(toPascalCase(str))
35
- }
36
-
37
- export function toConstantCase(str: string): string {
38
- return extractWords(str).map(toUpperCase).join('_')
39
- }
40
-
41
- export function toLowerCase(str: string): string {
42
- return str.toLowerCase()
43
- }
44
-
45
- export function toUpperCase(str: string): string {
46
- return str.toUpperCase()
47
- }
48
-
49
- function extractWords(str: string): string[] {
50
- const processedStr = str
51
- .replace(/([a-z0-9])([A-Z])/g, '$1 $2') // split camelCase
52
- .replace(/([A-Z])([A-Z][a-z])/g, '$1 $2') // split ALLCAPSWords
53
- .replace(/([0-9])([A-Za-z])/g, '$1 $2') // split number followed by letter
54
- .replace(/[^a-zA-Z0-9]+/g, ' ') // replace non-alphanumeric with space
55
- .trim() // trim leading/trailing spaces
56
-
57
- return processedStr
58
- ? processedStr.split(/\s+/) // split by spaces
59
- : [] // Avoid returning [''] for empty strings
60
- }
61
-
62
- export function asRelativePath(from: string, to: string) {
63
- const relPath = relative(from, to)
64
- return relPath.startsWith('./') || relPath.startsWith('../')
65
- ? relPath
66
- : `./${relPath}`
67
- }
68
-
69
- export function startsWithDigit(str: string) {
70
- const code = str.charCodeAt(0)
71
- return code >= 48 && code <= 57 // '0' to '9'
72
- }
@@ -1,13 +0,0 @@
1
- {
2
- "extends": ["../../../tsconfig/node.json"],
3
- "include": ["./src"],
4
- "exclude": ["**/*.test.ts"],
5
- "compilerOptions": {
6
- "noImplicitAny": true,
7
- "importHelpers": true,
8
- "target": "ES2023",
9
- "rootDir": "./src",
10
- "outDir": "./dist",
11
- "types": ["node"],
12
- },
13
- }
package/tsconfig.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "include": [],
3
- "references": [
4
- { "path": "./tsconfig.build.json" },
5
- { "path": "./tsconfig.tests.json" },
6
- ],
7
- }
@@ -1,8 +0,0 @@
1
- {
2
- "extends": "../../../tsconfig/vitest.json",
3
- "include": ["./tests", "./src/**/*.test.ts"],
4
- "compilerOptions": {
5
- "noImplicitAny": true,
6
- "rootDir": "./",
7
- },
8
- }