@everystack/cli 0.4.1 → 0.4.2
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.
package/package.json
CHANGED
|
@@ -45,7 +45,7 @@ const PLAIN_IDENT = /^[a-z_][a-z0-9_$]*$/;
|
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
47
|
* Derived symbols are camelCase VERBATIM — never singularized (deliberately distinct
|
|
48
|
-
* from modelVarName's rule; a matview named `
|
|
48
|
+
* from modelVarName's rule; a matview named `user_sessions` is `userSessions`).
|
|
49
49
|
* NAMING CONTRACT — a rename here breaks consumer splices; pinned by
|
|
50
50
|
* naming-contract.test.ts.
|
|
51
51
|
*/
|
package/src/cli/model-render.ts
CHANGED
|
@@ -186,7 +186,7 @@ export function modelVarName(table: string): string {
|
|
|
186
186
|
* `author_id` → `authorId` — a SQL column to its field key, LOSSLESSLY: the compiler's
|
|
187
187
|
* snake_case must reconstruct the exact column (`snake(key) === column`, always). Only a
|
|
188
188
|
* letter after `_` camelizes, because only a capital letter survives the trip back — an
|
|
189
|
-
* underscore before a digit is preserved (`
|
|
189
|
+
* underscore before a digit is preserved (`percentile_100` stays `percentile_100`,
|
|
190
190
|
* `top_3_best` → `top_3Best`). Swallowing it (the old `_([a-z0-9])` rule) generated a
|
|
191
191
|
* phantom rename for every digit-boundary column and COLLIDED distinct columns
|
|
192
192
|
* (`a_1` and `a1`) onto one key.
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { defineModel, field, can, index, defineModule, sql, arg, defineFunction, defineMaterializedView, defineSequence, defineView } from '@everystack/model';
|
|
2
|
-
|
|
3
|
-
export const PdrPost = defineModel('pdr_posts', {
|
|
4
|
-
abilities: [can('read'), can('manage', { role: 'admin' })],
|
|
5
|
-
fields: {
|
|
6
|
-
id: field.integer().primaryKey(),
|
|
7
|
-
title: field.text().notNull(),
|
|
8
|
-
tags: field.text().array().notNull().default("{}"),
|
|
9
|
-
},
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
export const pdrTicketSeq = defineSequence('pdr_ticket_seq', { start: 500 });
|
|
13
|
-
|
|
14
|
-
export const pdrsPdrArea = defineFunction('pdrs.pdr_area', {
|
|
15
|
-
args: [arg('w', 'integer'), arg('h', 'integer')],
|
|
16
|
-
returns: 'integer',
|
|
17
|
-
language: 'sql',
|
|
18
|
-
volatility: 'immutable',
|
|
19
|
-
abilities: [can('execute', { role: 'authenticated' })],
|
|
20
|
-
body: sql`SELECT w * h`,
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
export const pdrBoard = defineMaterializedView('pdr_board', {
|
|
24
|
-
abilities: [can('read')],
|
|
25
|
-
dependsOn: [PdrPost],
|
|
26
|
-
indexes: [index('tags').using('gin')],
|
|
27
|
-
as: sql`SELECT tags,
|
|
28
|
-
count(*) AS n
|
|
29
|
-
FROM pdr_posts
|
|
30
|
-
GROUP BY tags`,
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
export const pdrScore = defineFunction('pdr_score', {
|
|
34
|
-
args: [arg('points', 'integer', { default: sql`1` })],
|
|
35
|
-
returns: 'integer',
|
|
36
|
-
language: 'sql',
|
|
37
|
-
volatility: 'stable',
|
|
38
|
-
abilities: [can('execute', { role: 'authenticated' })],
|
|
39
|
-
body: sql`SELECT points * 2`,
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
export const pdrTitles = defineView('pdr_titles', {
|
|
43
|
-
securityInvoker: false,
|
|
44
|
-
abilities: [can('read')],
|
|
45
|
-
dependsOn: [PdrPost],
|
|
46
|
-
as: sql`SELECT id,
|
|
47
|
-
title
|
|
48
|
-
FROM pdr_posts`,
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
export const models = [PdrPost];
|
|
52
|
-
|
|
53
|
-
export const sequences = [pdrTicketSeq];
|
|
54
|
-
|
|
55
|
-
export const derived = [pdrsPdrArea, pdrBoard, pdrScore, pdrTitles];
|
|
56
|
-
|
|
57
|
-
export const appModule = defineModule({ models, sequences, derived });
|
|
58
|
-
|
|
59
|
-
export const modules = [appModule];
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { defineModel, field, unique, check, index, foreignKey, defineModule, sql } from '@everystack/model';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
|
|
4
|
-
export const RtAccount = defineModel('rt_accounts', {
|
|
5
|
-
// Declare the read model — db:check fails this model until its authz is authored:
|
|
6
|
-
// abilities: [can('read')], // public data
|
|
7
|
-
// abilities: [can('read', { owner: '<column>' })], // rows owned by a user
|
|
8
|
-
// private: true, // not part of the data API
|
|
9
|
-
fields: {
|
|
10
|
-
id: field.uuid().primaryKey().defaultRandom(),
|
|
11
|
-
email: field.text().notNull().unique(),
|
|
12
|
-
displayName: field.text().notNull(),
|
|
13
|
-
age: field.integer(),
|
|
14
|
-
balance: field.bigint().notNull().default(0),
|
|
15
|
-
creditLimit: field.numeric(12, 2),
|
|
16
|
-
score: field.numeric(8),
|
|
17
|
-
slug: field.varchar(255).notNull(),
|
|
18
|
-
region: field.varchar(),
|
|
19
|
-
bio: field.text().validate(z.string().max(160)),
|
|
20
|
-
active: field.boolean().notNull().default(true),
|
|
21
|
-
role: field.text().notNull().default("member"),
|
|
22
|
-
status: field.enum('account_status', ['active', 'suspended', 'closed']).notNull().default("active"),
|
|
23
|
-
metadata: field.jsonb(),
|
|
24
|
-
bornOn: field.date(),
|
|
25
|
-
createdAt: field.timestamptz().notNull().defaultNow(),
|
|
26
|
-
updatedAt: field.timestamp(),
|
|
27
|
-
},
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
export const RtMetricArchive = defineModel('rt_metric_archives', {
|
|
31
|
-
// Declare the read model — db:check fails this model until its authz is authored:
|
|
32
|
-
// abilities: [can('read')], // public data
|
|
33
|
-
// abilities: [can('read', { owner: '<column>' })], // rows owned by a user
|
|
34
|
-
// private: true, // not part of the data API
|
|
35
|
-
fields: {
|
|
36
|
-
id: field.integer().primaryKey().defaultSql(sql`nextval('rt_metrics_id_seq'::regclass)`),
|
|
37
|
-
note: field.text(),
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
export const RtMetric = defineModel('rt_metrics', {
|
|
42
|
-
// Declare the read model — db:check fails this model until its authz is authored:
|
|
43
|
-
// abilities: [can('read')], // public data
|
|
44
|
-
// abilities: [can('read', { owner: '<column>' })], // rows owned by a user
|
|
45
|
-
// private: true, // not part of the data API
|
|
46
|
-
fields: {
|
|
47
|
-
id: field.serial().primaryKey(),
|
|
48
|
-
noteId: field.uuid().notNull().references(() => RtNote),
|
|
49
|
-
coverRate: field.real(),
|
|
50
|
-
meanMiss: field.doublePrecision().notNull(),
|
|
51
|
-
counter: field.bigserial(),
|
|
52
|
-
yardline_100: field.integer(),
|
|
53
|
-
top_3Best: field.integer(),
|
|
54
|
-
tags: field.text().array(),
|
|
55
|
-
},
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
export const RtNoteTag = defineModel('rt_note_tags', {
|
|
59
|
-
// Declare the read model — db:check fails this model until its authz is authored:
|
|
60
|
-
// abilities: [can('read')], // public data
|
|
61
|
-
// abilities: [can('read', { owner: '<column>' })], // rows owned by a user
|
|
62
|
-
// private: true, // not part of the data API
|
|
63
|
-
fields: {
|
|
64
|
-
noteId: field.uuid().primaryKey().references(() => RtNote),
|
|
65
|
-
label: field.text().primaryKey(),
|
|
66
|
-
},
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
export const RtNote = defineModel('rt_notes', {
|
|
70
|
-
// Declare the read model — db:check fails this model until its authz is authored:
|
|
71
|
-
// abilities: [can('read')], // public data
|
|
72
|
-
// abilities: [can('read', { owner: '<column>' })], // rows owned by a user
|
|
73
|
-
// private: true, // not part of the data API
|
|
74
|
-
fields: {
|
|
75
|
-
id: field.uuid().primaryKey().defaultRandom(),
|
|
76
|
-
accountId: field.uuid().notNull().references(() => RtAccount, { onDelete: 'cascade' }),
|
|
77
|
-
parentId: field.uuid().references(() => RtNote, { onDelete: 'set null', onUpdate: 'cascade' }),
|
|
78
|
-
title: field.text().notNull(),
|
|
79
|
-
body: field.text(),
|
|
80
|
-
pinned: field.boolean().notNull().default(false),
|
|
81
|
-
createdAt: field.timestamptz().notNull().defaultNow(),
|
|
82
|
-
},
|
|
83
|
-
constraints: [
|
|
84
|
-
unique('accountId', 'title'),
|
|
85
|
-
check(sql`char_length(title) > 0`),
|
|
86
|
-
index('createdAt').where(sql`pinned = true`),
|
|
87
|
-
index('parentId'),
|
|
88
|
-
],
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
export const RtTagLink = defineModel('rt_tag_links', {
|
|
92
|
-
// Declare the read model — db:check fails this model until its authz is authored:
|
|
93
|
-
// abilities: [can('read')], // public data
|
|
94
|
-
// abilities: [can('read', { owner: '<column>' })], // rows owned by a user
|
|
95
|
-
// private: true, // not part of the data API
|
|
96
|
-
fields: {
|
|
97
|
-
id: field.uuid().primaryKey().defaultRandom(),
|
|
98
|
-
noteId: field.uuid().notNull(),
|
|
99
|
-
label: field.text().notNull(),
|
|
100
|
-
},
|
|
101
|
-
constraints: [
|
|
102
|
-
foreignKey(['noteId', 'label'], () => RtNoteTag, ['noteId', 'label'], { onDelete: 'cascade' }),
|
|
103
|
-
],
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
export const RtTicket = defineModel('rt_tickets', {
|
|
107
|
-
// Declare the read model — db:check fails this model until its authz is authored:
|
|
108
|
-
// abilities: [can('read')], // public data
|
|
109
|
-
// abilities: [can('read', { owner: '<column>' })], // rows owned by a user
|
|
110
|
-
// private: true, // not part of the data API
|
|
111
|
-
fields: {
|
|
112
|
-
id: field.uuid().primaryKey().defaultRandom(),
|
|
113
|
-
ticketNumber: field.bigint().notNull().defaultSql(sql`nextval('rt_ticket_counter'::regclass)`),
|
|
114
|
-
},
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
export const models = [RtAccount, RtMetricArchive, RtMetric, RtNoteTag, RtNote, RtTagLink, RtTicket];
|
|
118
|
-
|
|
119
|
-
export const appModule = defineModule({ models });
|
|
120
|
-
|
|
121
|
-
export const modules = [appModule];
|