rizolang 0.0.0-stage → 0.2.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 (53) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +399 -2
  3. package/build/src/ast.d.ts +133 -0
  4. package/build/src/ast.js +4 -0
  5. package/build/src/ast.js.map +1 -0
  6. package/build/src/bin.d.ts +2 -0
  7. package/build/src/bin.js +8 -0
  8. package/build/src/bin.js.map +1 -0
  9. package/build/src/check-api.d.ts +97 -0
  10. package/build/src/check-api.js +506 -0
  11. package/build/src/check-api.js.map +1 -0
  12. package/build/src/checker.d.ts +53 -0
  13. package/build/src/checker.js +235 -0
  14. package/build/src/checker.js.map +1 -0
  15. package/build/src/cli.d.ts +11 -0
  16. package/build/src/cli.js +94 -0
  17. package/build/src/cli.js.map +1 -0
  18. package/build/src/compiler.d.ts +36 -0
  19. package/build/src/compiler.js +61 -0
  20. package/build/src/compiler.js.map +1 -0
  21. package/build/src/diagnostics.d.ts +35 -0
  22. package/build/src/diagnostics.js +69 -0
  23. package/build/src/diagnostics.js.map +1 -0
  24. package/build/src/emit/routes.d.ts +20 -0
  25. package/build/src/emit/routes.js +246 -0
  26. package/build/src/emit/routes.js.map +1 -0
  27. package/build/src/emit/sql.d.ts +12 -0
  28. package/build/src/emit/sql.js +83 -0
  29. package/build/src/emit/sql.js.map +1 -0
  30. package/build/src/emit/typescript.d.ts +13 -0
  31. package/build/src/emit/typescript.js +74 -0
  32. package/build/src/emit/typescript.js.map +1 -0
  33. package/build/src/lexer.d.ts +17 -0
  34. package/build/src/lexer.js +124 -0
  35. package/build/src/lexer.js.map +1 -0
  36. package/build/src/parser.d.ts +17 -0
  37. package/build/src/parser.js +399 -0
  38. package/build/src/parser.js.map +1 -0
  39. package/build/src/types.d.ts +42 -0
  40. package/build/src/types.js +77 -0
  41. package/build/src/types.js.map +1 -0
  42. package/build/src/version.d.ts +2 -0
  43. package/build/src/version.js +3 -0
  44. package/build/src/version.js.map +1 -0
  45. package/docs/SPEC-COMPACT.md +148 -0
  46. package/docs/SPEC.md +597 -0
  47. package/package.json +48 -4
  48. package/runtime/password.ts +58 -0
  49. package/runtime/ratelimit.ts +53 -0
  50. package/runtime/server.ts +449 -0
  51. package/runtime/session.ts +48 -0
  52. package/runtime/types.ts +76 -0
  53. package/runtime/validate.ts +133 -0
@@ -0,0 +1,133 @@
1
+ import type { Span } from "./diagnostics.js";
2
+ /** Syntax tree produced by the parser. Names and types are not validated yet. */
3
+ export interface Program {
4
+ readonly models: readonly ModelDecl[];
5
+ readonly auths: readonly AuthDecl[];
6
+ readonly apis: readonly ApiDecl[];
7
+ }
8
+ export interface ModelDecl {
9
+ readonly name: string;
10
+ readonly nameSpan: Span;
11
+ readonly fields: readonly FieldDecl[];
12
+ }
13
+ export interface FieldDecl {
14
+ readonly name: string;
15
+ readonly nameSpan: Span;
16
+ /** A field type (Text, Email, ...) or the name of another model (a link). */
17
+ readonly typeName: string;
18
+ readonly typeSpan: Span;
19
+ readonly modifiers: readonly Modifier[];
20
+ }
21
+ export type Modifier = {
22
+ readonly kind: "unique" | "optional" | "private";
23
+ readonly span: Span;
24
+ } | {
25
+ readonly kind: "min" | "max";
26
+ readonly value: number;
27
+ readonly span: Span;
28
+ readonly valueSpan: Span;
29
+ };
30
+ export type ModifierKind = Modifier["kind"];
31
+ export declare const MODIFIER_NAMES: readonly ModifierKind[];
32
+ /** `auth User by email` */
33
+ export interface AuthDecl {
34
+ readonly span: Span;
35
+ readonly model: string;
36
+ readonly modelSpan: Span;
37
+ readonly field: string;
38
+ readonly fieldSpan: Span;
39
+ }
40
+ export declare const HTTP_METHODS: readonly ["GET", "POST", "PUT", "PATCH", "DELETE"];
41
+ export type HttpMethod = (typeof HTTP_METHODS)[number];
42
+ /** `api GET /posts/:id -> Post.public { ... }` */
43
+ export interface ApiDecl {
44
+ readonly span: Span;
45
+ readonly method: HttpMethod;
46
+ readonly methodSpan: Span;
47
+ readonly path: string;
48
+ readonly pathSpan: Span;
49
+ /** Undefined when the endpoint returns nothing (`api DELETE /posts/:id { ... }`). */
50
+ readonly returns: ReturnType | undefined;
51
+ readonly statements: readonly Statement[];
52
+ /** Span of the closing brace, for errors about missing statements. */
53
+ readonly endSpan: Span;
54
+ }
55
+ export interface ReturnType {
56
+ readonly list: boolean;
57
+ readonly model: string;
58
+ readonly modelSpan: Span;
59
+ /** The word after the dot; must be "public". */
60
+ readonly view: string;
61
+ readonly viewSpan: Span;
62
+ readonly span: Span;
63
+ }
64
+ export type Statement = {
65
+ readonly kind: "public";
66
+ readonly span: Span;
67
+ } | {
68
+ readonly kind: "requiresLogin";
69
+ readonly span: Span;
70
+ } | {
71
+ readonly kind: "requiresOwner";
72
+ readonly span: Span;
73
+ readonly field: string;
74
+ readonly fieldSpan: Span;
75
+ } | {
76
+ readonly kind: "return";
77
+ readonly span: Span;
78
+ readonly query: Query;
79
+ };
80
+ export declare const QUERY_ACTIONS: readonly ["find", "list", "create", "update", "delete"];
81
+ export type QueryAction = (typeof QUERY_ACTIONS)[number];
82
+ /** `db.Post.list(author = me, order title desc, limit 20)` */
83
+ export interface Query {
84
+ readonly span: Span;
85
+ readonly model: string;
86
+ readonly modelSpan: Span;
87
+ readonly action: string;
88
+ readonly actionSpan: Span;
89
+ readonly args: readonly QueryArg[];
90
+ }
91
+ export type QueryArg =
92
+ /** A bare name: a path parameter (`id`) or `body`. */
93
+ {
94
+ readonly kind: "name";
95
+ readonly name: string;
96
+ readonly span: Span;
97
+ }
98
+ /** `field = value` */
99
+ | {
100
+ readonly kind: "assign";
101
+ readonly field: string;
102
+ readonly fieldSpan: Span;
103
+ readonly value: Value;
104
+ readonly span: Span;
105
+ }
106
+ /** `order field` or `order field desc` */
107
+ | {
108
+ readonly kind: "order";
109
+ readonly field: string;
110
+ readonly fieldSpan: Span;
111
+ readonly descending: boolean;
112
+ readonly span: Span;
113
+ }
114
+ /** `limit 20` */
115
+ | {
116
+ readonly kind: "limit";
117
+ readonly value: number;
118
+ readonly valueSpan: Span;
119
+ readonly span: Span;
120
+ };
121
+ export type Value = {
122
+ readonly kind: "name";
123
+ readonly name: string;
124
+ readonly span: Span;
125
+ } | {
126
+ readonly kind: "int";
127
+ readonly value: number;
128
+ readonly span: Span;
129
+ } | {
130
+ readonly kind: "bool";
131
+ readonly value: boolean;
132
+ readonly span: Span;
133
+ };
@@ -0,0 +1,4 @@
1
+ export const MODIFIER_NAMES = ["unique", "optional", "private", "min", "max"];
2
+ export const HTTP_METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE"];
3
+ export const QUERY_ACTIONS = ["find", "list", "create", "update", "delete"];
4
+ //# sourceMappingURL=ast.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ast.js","sourceRoot":"","sources":["../../src/ast.ts"],"names":[],"mappings":"AA+BA,MAAM,CAAC,MAAM,cAAc,GAA4B,CAAC,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;AAWvG,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAU,CAAC;AAiC/E,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAU,CAAC"}
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+ import { run } from "./cli.js";
3
+ process.exitCode = run(process.argv.slice(2), {
4
+ cwd: process.cwd(),
5
+ stdout: (text) => process.stdout.write(text),
6
+ stderr: (text) => process.stderr.write(text),
7
+ });
8
+ //# sourceMappingURL=bin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin.js","sourceRoot":"","sources":["../../src/bin.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,OAAO,CAAC,QAAQ,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;IAC5C,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE;IAClB,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC;IAC5C,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC;CAC7C,CAAC,CAAC"}
@@ -0,0 +1,97 @@
1
+ import { type ApiDecl, type AuthDecl, type HttpMethod } from "./ast.js";
2
+ import { type ResolvedField, type ResolvedModel } from "./checker.js";
3
+ import { type Span } from "./diagnostics.js";
4
+ /**
5
+ * Checks `auth` and `api` declarations. The rules here are what make
6
+ * endpoints safe by construction:
7
+ * - every endpoint says `public` or `requires login`;
8
+ * - endpoints return only `.public` views;
9
+ * - a link to the auth model is set by the server (`= me`), never by the client;
10
+ * - `requires owner` turns into a WHERE clause, so it cannot be bypassed,
11
+ * and it is required to change or delete records that belong to users;
12
+ * - GET never changes data.
13
+ */
14
+ export interface ResolvedAuth {
15
+ readonly model: ResolvedModel;
16
+ /** The `by` field: Email, unique, required. */
17
+ readonly loginField: ResolvedField;
18
+ readonly passwordField: ResolvedField;
19
+ }
20
+ export type PathSegment = {
21
+ readonly kind: "static";
22
+ readonly value: string;
23
+ } | {
24
+ readonly kind: "param";
25
+ readonly name: string;
26
+ };
27
+ /** Types a path parameter can have, inferred from where it is used. */
28
+ export type ParamType = "ID" | "Number" | "Bool" | "Text" | "Email";
29
+ export interface PathParam {
30
+ readonly name: string;
31
+ readonly type: ParamType;
32
+ }
33
+ export type ResolvedValue = {
34
+ readonly kind: "me";
35
+ } | {
36
+ readonly kind: "param";
37
+ readonly name: string;
38
+ } | {
39
+ readonly kind: "int";
40
+ readonly value: number;
41
+ } | {
42
+ readonly kind: "bool";
43
+ readonly value: boolean;
44
+ };
45
+ export interface FieldValue {
46
+ readonly field: ResolvedField;
47
+ readonly value: ResolvedValue;
48
+ }
49
+ export type ResolvedQuery = {
50
+ readonly action: "find";
51
+ readonly model: ResolvedModel;
52
+ readonly idParam: string;
53
+ } | {
54
+ readonly action: "list";
55
+ readonly model: ResolvedModel;
56
+ readonly filters: readonly FieldValue[];
57
+ /** Undefined field means "order by id". */
58
+ readonly order: {
59
+ readonly field: ResolvedField | undefined;
60
+ readonly descending: boolean;
61
+ };
62
+ readonly limit: number;
63
+ } | {
64
+ readonly action: "create";
65
+ readonly model: ResolvedModel;
66
+ /** Fields taken from the request body. */
67
+ readonly bodyFields: readonly ResolvedField[];
68
+ /** Fields set by the server (`author = me`). */
69
+ readonly assigns: readonly FieldValue[];
70
+ } | {
71
+ readonly action: "update";
72
+ readonly model: ResolvedModel;
73
+ readonly idParam: string;
74
+ /** Fields that may be changed; all are optional in the body. */
75
+ readonly bodyFields: readonly ResolvedField[];
76
+ } | {
77
+ readonly action: "delete";
78
+ readonly model: ResolvedModel;
79
+ readonly idParam: string;
80
+ };
81
+ export interface ResolvedApi {
82
+ readonly method: HttpMethod;
83
+ readonly path: string;
84
+ readonly segments: readonly PathSegment[];
85
+ readonly params: readonly PathParam[];
86
+ readonly access: "public" | "login";
87
+ /** Link field that must equal the logged-in user (`requires owner author`). */
88
+ readonly owner: ResolvedField | undefined;
89
+ readonly returns: "one" | "list" | "none";
90
+ readonly query: ResolvedQuery;
91
+ }
92
+ type Err = (code: string, span: Span, message: string, fix: string) => void;
93
+ export declare const DEFAULT_LIST_LIMIT = 50;
94
+ export declare const MAX_LIST_LIMIT = 100;
95
+ export declare function checkAuth(auths: readonly AuthDecl[], models: readonly ResolvedModel[], err: Err): ResolvedAuth | undefined;
96
+ export declare function checkApis(apis: readonly ApiDecl[], models: readonly ResolvedModel[], auth: ResolvedAuth | undefined, authDeclared: boolean, err: Err): ResolvedApi[];
97
+ export {};