fastscript 1.0.0 → 2.0.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 (109) hide show
  1. package/CHANGELOG.md +32 -7
  2. package/LICENSE +33 -21
  3. package/README.md +567 -73
  4. package/node_modules/@fastscript/core-private/BOUNDARY.json +15 -0
  5. package/node_modules/@fastscript/core-private/README.md +5 -0
  6. package/node_modules/@fastscript/core-private/package.json +34 -0
  7. package/node_modules/@fastscript/core-private/src/asset-optimizer.mjs +67 -0
  8. package/node_modules/@fastscript/core-private/src/audit-log.mjs +50 -0
  9. package/node_modules/@fastscript/core-private/src/auth-flows.mjs +29 -0
  10. package/node_modules/@fastscript/core-private/src/auth.mjs +115 -0
  11. package/node_modules/@fastscript/core-private/src/bench.mjs +45 -0
  12. package/node_modules/@fastscript/core-private/src/build.mjs +670 -0
  13. package/node_modules/@fastscript/core-private/src/cache.mjs +248 -0
  14. package/node_modules/@fastscript/core-private/src/check.mjs +22 -0
  15. package/node_modules/@fastscript/core-private/src/cli.mjs +95 -0
  16. package/node_modules/@fastscript/core-private/src/compat.mjs +128 -0
  17. package/node_modules/@fastscript/core-private/src/create.mjs +278 -0
  18. package/node_modules/@fastscript/core-private/src/csp.mjs +26 -0
  19. package/node_modules/@fastscript/core-private/src/db-cli.mjs +185 -0
  20. package/node_modules/@fastscript/core-private/src/db-postgres-collection.mjs +110 -0
  21. package/node_modules/@fastscript/core-private/src/db-postgres.mjs +40 -0
  22. package/node_modules/@fastscript/core-private/src/db.mjs +103 -0
  23. package/node_modules/@fastscript/core-private/src/deploy.mjs +662 -0
  24. package/node_modules/@fastscript/core-private/src/dev.mjs +5 -0
  25. package/node_modules/@fastscript/core-private/src/docs-search.mjs +35 -0
  26. package/node_modules/@fastscript/core-private/src/env.mjs +118 -0
  27. package/node_modules/@fastscript/core-private/src/export.mjs +83 -0
  28. package/node_modules/@fastscript/core-private/src/fs-diagnostics.mjs +70 -0
  29. package/node_modules/@fastscript/core-private/src/fs-error-codes.mjs +141 -0
  30. package/node_modules/@fastscript/core-private/src/fs-formatter.mjs +66 -0
  31. package/node_modules/@fastscript/core-private/src/fs-linter.mjs +274 -0
  32. package/node_modules/@fastscript/core-private/src/fs-normalize.mjs +91 -0
  33. package/node_modules/@fastscript/core-private/src/fs-parser.mjs +980 -0
  34. package/node_modules/@fastscript/core-private/src/generated/docs-search-index.mjs +3182 -0
  35. package/node_modules/@fastscript/core-private/src/i18n.mjs +25 -0
  36. package/node_modules/@fastscript/core-private/src/interop.mjs +16 -0
  37. package/node_modules/@fastscript/core-private/src/jobs.mjs +378 -0
  38. package/node_modules/@fastscript/core-private/src/logger.mjs +27 -0
  39. package/node_modules/@fastscript/core-private/src/metrics.mjs +45 -0
  40. package/node_modules/@fastscript/core-private/src/middleware.mjs +14 -0
  41. package/node_modules/@fastscript/core-private/src/migrate.mjs +81 -0
  42. package/node_modules/@fastscript/core-private/src/migration-wizard.mjs +16 -0
  43. package/node_modules/@fastscript/core-private/src/module-loader.mjs +46 -0
  44. package/node_modules/@fastscript/core-private/src/oauth-providers.mjs +103 -0
  45. package/node_modules/@fastscript/core-private/src/observability.mjs +21 -0
  46. package/node_modules/@fastscript/core-private/src/plugins.mjs +194 -0
  47. package/node_modules/@fastscript/core-private/src/retention.mjs +57 -0
  48. package/node_modules/@fastscript/core-private/src/routes.mjs +178 -0
  49. package/node_modules/@fastscript/core-private/src/scheduler.mjs +104 -0
  50. package/node_modules/@fastscript/core-private/src/security.mjs +233 -0
  51. package/node_modules/@fastscript/core-private/src/server-runtime.mjs +849 -0
  52. package/node_modules/@fastscript/core-private/src/serverless-handler.mjs +20 -0
  53. package/node_modules/@fastscript/core-private/src/session-policy.mjs +38 -0
  54. package/node_modules/@fastscript/core-private/src/start.mjs +10 -0
  55. package/node_modules/@fastscript/core-private/src/storage.mjs +155 -0
  56. package/node_modules/@fastscript/core-private/src/style-primitives.mjs +538 -0
  57. package/node_modules/@fastscript/core-private/src/style-system.mjs +461 -0
  58. package/node_modules/@fastscript/core-private/src/tenant.mjs +55 -0
  59. package/node_modules/@fastscript/core-private/src/typecheck.mjs +1464 -0
  60. package/node_modules/@fastscript/core-private/src/validate.mjs +22 -0
  61. package/node_modules/@fastscript/core-private/src/validation.mjs +88 -0
  62. package/node_modules/@fastscript/core-private/src/webhook.mjs +81 -0
  63. package/node_modules/@fastscript/core-private/src/worker.mjs +24 -0
  64. package/package.json +86 -13
  65. package/src/asset-optimizer.mjs +67 -0
  66. package/src/audit-log.mjs +50 -0
  67. package/src/auth.mjs +1 -115
  68. package/src/bench.mjs +20 -7
  69. package/src/build.mjs +1 -234
  70. package/src/cache.mjs +210 -20
  71. package/src/cli.mjs +29 -5
  72. package/src/compat.mjs +8 -10
  73. package/src/create.mjs +71 -17
  74. package/src/csp.mjs +26 -0
  75. package/src/db-cli.mjs +152 -8
  76. package/src/db-postgres-collection.mjs +110 -0
  77. package/src/deploy.mjs +1 -65
  78. package/src/docs-search.mjs +35 -0
  79. package/src/env.mjs +34 -5
  80. package/src/fs-diagnostics.mjs +70 -0
  81. package/src/fs-error-codes.mjs +126 -0
  82. package/src/fs-formatter.mjs +66 -0
  83. package/src/fs-linter.mjs +274 -0
  84. package/src/fs-normalize.mjs +21 -238
  85. package/src/fs-parser.mjs +1 -0
  86. package/src/generated/docs-search-index.mjs +3220 -0
  87. package/src/i18n.mjs +25 -0
  88. package/src/jobs.mjs +283 -32
  89. package/src/metrics.mjs +45 -0
  90. package/src/migration-wizard.mjs +16 -0
  91. package/src/module-loader.mjs +11 -12
  92. package/src/oauth-providers.mjs +103 -0
  93. package/src/plugins.mjs +194 -0
  94. package/src/retention.mjs +57 -0
  95. package/src/routes.mjs +178 -0
  96. package/src/scheduler.mjs +104 -0
  97. package/src/security.mjs +197 -19
  98. package/src/server-runtime.mjs +1 -339
  99. package/src/serverless-handler.mjs +20 -0
  100. package/src/session-policy.mjs +38 -0
  101. package/src/storage.mjs +1 -56
  102. package/src/style-system.mjs +461 -0
  103. package/src/tenant.mjs +55 -0
  104. package/src/typecheck.mjs +1 -0
  105. package/src/validate.mjs +5 -1
  106. package/src/validation.mjs +14 -5
  107. package/src/webhook.mjs +1 -71
  108. package/src/worker.mjs +23 -4
  109. package/src/language-spec.mjs +0 -58
@@ -1,232 +1,21 @@
1
- const reactiveDeclPattern = /^(\s*)~([A-Za-z_$][\w$]*)(\s*=\s*.*)$/;
2
- const stateDeclPattern = /^(\s*)state\s+([A-Za-z_$][\w$]*)(\s*=\s*.*)$/;
3
- const fnDeclPattern = /^(\s*)(export\s+)?fn\s+([A-Za-z_$][\w$]*)\s*\(/;
4
- const reactiveStartPattern = /^\s*~/;
5
- const stateStartPattern = /^\s*state\b/;
6
- const emptyImportClausePattern = /^\s*import\s*\{\s*\}\s*from\s*["'][^"']+["']/;
7
- const invalidFnPattern = /^\s*(export\s+)?fn\b(?!\s+[A-Za-z_$][\w$]*\s*\()/;
8
- const relativeJsImportPattern = /from\s+["'](\.?\.?\/[^"']+)\.(js|jsx|ts|tsx)["']/;
9
-
10
- function nowMs() {
11
- if (typeof performance !== "undefined" && typeof performance.now === "function") {
12
- return performance.now();
13
- }
14
- return Date.now();
15
- }
16
-
17
- function toDiag(severity, line, col, code, message, fix = null) {
18
- return { severity, line, col, code, message, fix };
19
- }
20
-
21
- function normalizeFastScriptInternal(source, stats) {
22
- const lines = source.split(/\r?\n/);
23
- const out = [];
24
-
25
- for (const line of lines) {
26
- const m = line.match(reactiveDeclPattern);
27
- if (m) {
28
- stats.reactiveToLet += 1;
29
- out.push(`${m[1]}let ${m[2]}${m[3]}`);
30
- continue;
31
- }
32
- const s = line.match(stateDeclPattern);
33
- if (s) {
34
- stats.stateToLet += 1;
35
- out.push(`${s[1]}let ${s[2]}${s[3]}`);
36
- continue;
37
- }
38
- const f = line.match(fnDeclPattern);
39
- if (f) {
40
- stats.fnToFunction += 1;
41
- out.push(line.replace(fnDeclPattern, `${f[1]}${f[2] ?? ""}function ${f[3]}(`));
42
- continue;
43
- }
44
- out.push(line);
45
- }
46
-
47
- return out.join("\n");
48
- }
49
-
50
- export function analyzeFastScriptSource(source, { filename = "input.fs" } = {}) {
51
- const lines = source.split(/\r?\n/);
52
- const diagnostics = [];
53
- const declaredState = new Map();
54
- const isFs = /\.fs$/i.test(filename);
55
-
56
- for (let i = 0; i < lines.length; i += 1) {
57
- const lineNo = i + 1;
58
- const line = lines[i];
59
-
60
- if (!line.trim()) continue;
61
-
62
- const reactive = line.match(reactiveDeclPattern);
63
- if (reactive) {
64
- const name = reactive[2];
65
- const first = declaredState.get(name);
66
- if (first !== undefined) {
67
- diagnostics.push(
68
- toDiag(
69
- "warning",
70
- lineNo,
71
- Math.max(1, line.indexOf(name) + 1),
72
- "FS_DUP_STATE",
73
- `Duplicate reactive/state declaration "${name}" (first seen on line ${first})`,
74
- "Rename one declaration to avoid shadowing confusion.",
75
- ),
76
- );
77
- } else {
78
- declaredState.set(name, lineNo);
79
- }
80
- continue;
81
- }
82
-
83
- const state = line.match(stateDeclPattern);
84
- if (state) {
85
- const name = state[2];
86
- const first = declaredState.get(name);
87
- if (first !== undefined) {
88
- diagnostics.push(
89
- toDiag(
90
- "warning",
91
- lineNo,
92
- Math.max(1, line.indexOf(name) + 1),
93
- "FS_DUP_STATE",
94
- `Duplicate reactive/state declaration "${name}" (first seen on line ${first})`,
95
- "Rename one declaration to avoid shadowing confusion.",
96
- ),
97
- );
98
- } else {
99
- declaredState.set(name, lineNo);
100
- }
101
- continue;
102
- }
103
-
104
- if (reactiveStartPattern.test(line)) {
105
- diagnostics.push(
106
- toDiag(
107
- "warning",
108
- lineNo,
109
- Math.max(1, line.indexOf("~") + 1),
110
- "FS_BAD_REACTIVE",
111
- "Reactive declaration expected format: ~name = value",
112
- "Use: ~count = 0",
113
- ),
114
- );
115
- }
116
-
117
- if (stateStartPattern.test(line) && !stateDeclPattern.test(line)) {
118
- diagnostics.push(
119
- toDiag(
120
- "warning",
121
- lineNo,
122
- Math.max(1, line.indexOf("state") + 1),
123
- "FS_BAD_STATE",
124
- "State declaration expected format: state name = value",
125
- "Use: state count = 0",
126
- ),
127
- );
128
- }
129
-
130
- if (emptyImportClausePattern.test(line)) {
131
- diagnostics.push(
132
- toDiag(
133
- "error",
134
- lineNo,
135
- Math.max(1, line.indexOf("import") + 1),
136
- "FS_EMPTY_IMPORT",
137
- "Empty import clause is invalid.",
138
- 'Remove import or import at least one symbol: import { x } from "./mod.fs"',
139
- ),
140
- );
141
- }
142
-
143
- if (invalidFnPattern.test(line)) {
144
- diagnostics.push(
145
- toDiag(
146
- "warning",
147
- lineNo,
148
- Math.max(1, line.indexOf("fn") + 1),
149
- "FS_BAD_FN",
150
- 'Function shorthand expected format: fn name(args) { ... }',
151
- "Use: fn run(input) { ... }",
152
- ),
153
- );
154
- }
155
-
156
- if (isFs && relativeJsImportPattern.test(line)) {
157
- diagnostics.push(
158
- toDiag(
159
- "warning",
160
- lineNo,
161
- Math.max(1, line.indexOf("from") + 1),
162
- "FS_RELATIVE_JS_IMPORT",
163
- "Relative .js/.ts import inside .fs can hinder migration portability.",
164
- "Prefer extensionless imports or .fs extension for local modules.",
165
- ),
166
- );
167
- }
168
- }
169
-
170
- return diagnostics;
171
- }
172
-
173
- export function formatFastScriptDiagnostics(
174
- diagnostics,
175
- { filename = "input.fs", includeWarnings = true } = {},
176
- ) {
177
- const filtered = includeWarnings ? diagnostics : diagnostics.filter((d) => d.severity === "error");
178
- if (filtered.length === 0) return "";
179
- const lines = filtered.map((d) => {
180
- const sev = d.severity.toUpperCase();
181
- const fix = d.fix ? `\n fix: ${d.fix}` : "";
182
- return `[${sev}] ${d.code} ${filename}:${d.line}:${d.col}\n ${d.message}${fix}`;
1
+ import { compileFastScript } from "./fs-parser.mjs";
2
+
3
+ export function normalizeFastScript(source, options = {}) {
4
+ const { code } = compileFastScript(source, {
5
+ file: options.file || "",
6
+ mode: options.mode || "lenient",
7
+ recover: options.recover !== false,
8
+ inlineSourceMap: options.sourceMap === "inline",
183
9
  });
184
- return lines.join("\n");
185
- }
186
-
187
- export function createFastScriptDiagnosticError(
188
- diagnostics,
189
- { filename = "input.fs", includeWarnings = false } = {},
190
- ) {
191
- const printable = formatFastScriptDiagnostics(diagnostics, { filename, includeWarnings });
192
- const error = new Error(printable || `FastScript diagnostics failed for ${filename}`);
193
- error.code = "FASTSCRIPT_DIAGNOSTICS";
194
- error.diagnostics = diagnostics;
195
- return error;
196
- }
197
-
198
- export function normalizeFastScriptWithTelemetry(source, { filename = "input.fs", strict = false } = {}) {
199
- const startedAt = nowMs();
200
- const diagnostics = analyzeFastScriptSource(source, { filename });
201
- const errors = diagnostics.filter((d) => d.severity === "error");
202
- if (strict && errors.length > 0) {
203
- throw createFastScriptDiagnosticError(errors, { filename, includeWarnings: false });
204
- }
205
-
206
- const transformStats = {
207
- reactiveToLet: 0,
208
- stateToLet: 0,
209
- fnToFunction: 0,
210
- };
211
- const code = normalizeFastScriptInternal(source, transformStats);
212
- const durationMs = nowMs() - startedAt;
213
-
214
- return {
215
- code,
216
- diagnostics,
217
- stats: {
218
- lineCount: source.split(/\r?\n/).length,
219
- durationMs,
220
- ...transformStats,
221
- },
222
- };
10
+ return code;
223
11
  }
224
12
 
225
- export function normalizeFastScript(source) {
226
- return normalizeFastScriptInternal(source, {
227
- reactiveToLet: 0,
228
- stateToLet: 0,
229
- fnToFunction: 0,
13
+ export function normalizeFastScriptWithMetadata(source, options = {}) {
14
+ return compileFastScript(source, {
15
+ file: options.file || "",
16
+ mode: options.mode || "lenient",
17
+ recover: options.recover !== false,
18
+ inlineSourceMap: options.sourceMap === "inline",
230
19
  });
231
20
  }
232
21
 
@@ -253,26 +42,20 @@ export function stripTypeScriptHints(source) {
253
42
 
254
43
  if (/^\s*interface\s+[A-Za-z_$][\w$]*\s*[{]/.test(next) || /^\s*enum\s+[A-Za-z_$][\w$]*\s*[{]/.test(next)) {
255
44
  out.push(`// ${next.trim()} (removed by fastscript migrate)`);
45
+ skippingBlock = true;
256
46
  const opens = (next.match(/{/g) || []).length;
257
47
  const closes = (next.match(/}/g) || []).length;
258
- const depth = opens - closes;
259
- if (depth > 0) {
260
- skippingBlock = true;
261
- blockDepth = depth;
262
- }
48
+ blockDepth = Math.max(1, opens - closes);
263
49
  continue;
264
50
  }
265
51
 
266
52
  if (/^\s*type\s+[A-Za-z_$][\w$]*\s*=/.test(next)) {
267
53
  out.push(`// ${next.trim()} (removed by fastscript migrate)`);
268
54
  if (!next.includes(";") && next.includes("{")) {
55
+ skippingBlock = true;
269
56
  const opens = (next.match(/{/g) || []).length;
270
57
  const closes = (next.match(/}/g) || []).length;
271
- const depth = opens - closes;
272
- if (depth > 0) {
273
- skippingBlock = true;
274
- blockDepth = depth;
275
- }
58
+ blockDepth = Math.max(1, opens - closes);
276
59
  }
277
60
  continue;
278
61
  }
@@ -288,12 +71,12 @@ export function stripTypeScriptHints(source) {
288
71
  if (/\bfunction\b/.test(next) || /\)\s*=>/.test(next)) {
289
72
  next = next.replace(/\(([^)]*)\)/, (_, params) => {
290
73
  const cleaned = params.replace(
291
- /([A-Za-z_$][\w$]*)\s*:\s*([A-Za-z_$][\w$<>\[\]\|& ?. ]*)/g,
74
+ /([A-Za-z_$][\w$]*)\s*:\s*([A-Za-z_$][\w$<>\[\]\|&, ?.]*)/g,
292
75
  "$1",
293
76
  );
294
77
  return `(${cleaned})`;
295
78
  });
296
- next = next.replace(/\)\s*:\s*([A-Za-z_$][\w$<>\[\]\|& ?. ]*)\s*\{/g, ") {");
79
+ next = next.replace(/\)\s*:\s*([A-Za-z_$][\w$<>\[\]\|&, ?.]*)\s*\{/g, ") {");
297
80
  next = next.replace(/\bfunction\s+([A-Za-z_$][\w$]*)\s*<[^>]+>\s*\(/g, "function $1(");
298
81
  }
299
82
 
@@ -0,0 +1 @@
1
+ export * from "@fastscript/core-private/parser";