Skip to content

Commit 16b01c5

Browse files
committed
Removed the ving schema helper baseSchemaProps in favor of the new exports baseSchemaId, baseSchemaCreatedAt, and baseSchemaUpdatedAt. This is a breaking change that allows you to modify the base schema props in your schema.
1 parent 6e4582c commit 16b01c5

File tree

8 files changed

+78
-46
lines changed

8 files changed

+78
-46
lines changed

ving/docs/change-log.md

+16
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,22 @@ outline: deep
1111
* refactored to use Intl instead of date-fns #204
1212
* NOTE: If you are using the date formating strings in dateTime.mjs you will need to update them to use Intl instead of date-fns.
1313
* Fixed: note in docs how to reference drizzle schema #174
14+
* Removed the ving schema helper `baseSchemaProps` in favor of the new exports `baseSchemaId`, `baseSchemaCreatedAt`, and `baseSchemaUpdatedAt`. This is a breaking change that allows you to modify the base schema props in your schema.
15+
* NOTE: Update your Ving Schemas to use the new baseSchemaId, baseSchemaCreatedAt, and baseSchemaUpdatedAt exports in place of the baseSchemaProps array. In each of your ving schemas replace this:
16+
17+
```js
18+
...baseSchemaProps,
19+
```
20+
21+
With this:
22+
23+
```js
24+
{ ...baseSchemaId },
25+
{ ...baseSchemaCreatedAt },
26+
{ ...baseSchemaUpdatedAt },
27+
```
28+
29+
Also don't forget to update the imports in your schema files.
1430

1531
## December 2024
1632

ving/docs/subsystems/ving-schema.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ You'll find the schemas in `#ving/schema/schemas`. A schema looks like this:
1010
tableName: 'users',
1111
owner: ['$id', 'admin'],
1212
props: [
13-
...baseSchemaProps,
13+
{ ...baseSchemaId },
14+
{ ...baseSchemaCreatedAt },
15+
{ ...baseSchemaUpdatedAt },
1416
{
1517
type: "string",
1618
name: "username",
@@ -69,7 +71,7 @@ It can also contain any number of roles. By default there are 3 roles: `admin`,
6971
It can also defer to a parent object. So let's say you had a record called Invoice and another called LineItem. Each LineItem would have a parent relation to the Invoice called `invoice`. So you could then use `^invoice` (notice the carat) to indicate that you'd like to ask the Invoice if the User owns it, and if the answer is yes, then the LineItem will be considered to also be owned by that user. The carat means "look for a parent relation in the schema" and whatever comes after the carat is the name of that relation.
7072

7173
### props
72-
All schemas should have the base props of `id`, `createdAt`, and `updatedAt` by using `...baseSchemaProps`. After that it's up to you to add your own props to the list. There are many different types of props for different field types.
74+
All schemas should have the base props of `id`, `createdAt`, and `updatedAt` by using `{...baseSchemaId}`, `{...baseSchemaCreatedAt}`, and `{...baseSchemaUpdatedAt}`. After that it's up to you to add your own props to the list. There are many different types of props for different field types.
7375

7476
Props all have the fields `type`, `name`, `required`, `default`, `db`, `zod`, `view`, and `edit`, but can have more or less fields from there.
7577

ving/generator/vingschema.mjs

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ import { getContext, renderTemplate, toFile, after, inject } from '@feathersclou
22
import { camelCase } from 'scule';
33

44
const schemaTemplate = ({ name }) =>
5-
`import { baseSchemaProps, dbVarChar, zodString, dbEnum, dbBoolean, dbText, dbRelation, dbDateTime, dbTimestamp, dbBigInt, dbInt, dbUuid, dbJson, zodNumber, zodJsonObject, dbMediumText } from '../helpers.mjs';
5+
`import { baseSchemaId, baseSchemaCreatedAt, baseSchemaUpdatedAt, dbVarChar, zodString, dbEnum, dbBoolean, dbText, dbRelation, dbDateTime, dbTimestamp, dbBigInt, dbInt, dbUuid, dbJson, zodNumber, zodJsonObject, dbMediumText } from '../helpers.mjs';
66
77
export const ${camelCase(name)}Schema = {
88
kind: '${name}',
99
tableName: '${name.toLowerCase()}s',
1010
owner: ['$userId', 'admin'],
1111
props: [
12-
...baseSchemaProps,
12+
{ ...baseSchemaId },
13+
{ ...baseSchemaCreatedAt },
14+
{ ...baseSchemaUpdatedAt },
1315
// name field
1416
{
1517
type: "string",

ving/schema/helpers.mjs

+38-34
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ export const dbUuid = (prop) => {
218218
}
219219

220220
/**
221-
* Generates a drizzle schema field definition for a primary key prop. This is included in the `baseSchemaProps` and likely won't be used by you.
221+
* Generates a drizzle schema field definition for a primary key prop. This is included in the `baseSchemaId` and likely won't be used by you.
222222
* @param {Object} prop An object containing the properties of this prop
223223
* @returns a drizzle field schema definition
224224
*/
@@ -243,37 +243,41 @@ export const dbRelation = (prop) => {
243243
}
244244

245245
/**
246-
* The base set of props that all Ving schemas share. It includes an `id`, `createdAt`, and `updatedAt`.
246+
* The base set of props that all Ving schemas share.
247247
*/
248-
export const baseSchemaProps = [
249-
{
250-
type: "id",
251-
name: "id",
252-
required: false,
253-
default: undefined,
254-
db: (prop) => dbPk(prop),
255-
view: ['public'],
256-
edit: [],
257-
},
258-
{
259-
type: "date",
260-
name: "createdAt",
261-
filterRange: true,
262-
required: true,
263-
default: () => new Date(),
264-
db: (prop) => dbTimestamp(prop),
265-
view: ['public'],
266-
edit: [],
267-
},
268-
{
269-
type: "date",
270-
name: "updatedAt",
271-
filterRange: true,
272-
required: true,
273-
autoUpdate: true,
274-
default: () => new Date(),
275-
db: (prop) => dbTimestamp(prop),
276-
view: ['public'],
277-
edit: [],
278-
},
279-
];
248+
249+
// The Schema's unique identifier.
250+
export const baseSchemaId = {
251+
type: "id",
252+
name: "id",
253+
required: false,
254+
default: undefined,
255+
db: (prop) => dbPk(prop),
256+
view: ['public'],
257+
edit: [],
258+
};
259+
260+
// The Schema's creation timestamp.
261+
export const baseSchemaCreatedAt = {
262+
type: "date",
263+
name: "createdAt",
264+
filterRange: true,
265+
required: true,
266+
default: () => new Date(),
267+
db: (prop) => dbTimestamp(prop),
268+
view: ['public'],
269+
edit: [],
270+
};
271+
272+
// The Schema's last update timestamp.
273+
export const baseSchemaUpdatedAt = {
274+
type: "date",
275+
name: "updatedAt",
276+
filterRange: true,
277+
required: true,
278+
autoUpdate: true,
279+
default: () => new Date(),
280+
db: (prop) => dbTimestamp(prop),
281+
view: ['public'],
282+
edit: [],
283+
};

ving/schema/schemas/APIKey.mjs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
import { baseSchemaProps, dbVarChar, zodString, dbText, dbRelation } from '../helpers.mjs';
1+
import { baseSchemaId, baseSchemaCreatedAt, baseSchemaUpdatedAt, dbVarChar, zodString, dbText, dbRelation } from '../helpers.mjs';
22
import crypto from 'crypto';
33

44
export const apikeySchema = {
55
kind: 'APIKey',
66
tableName: 'apikeys',
77
owner: ['$userId', 'admin'],
88
props: [
9-
...baseSchemaProps,
9+
{ ...baseSchemaId },
10+
{ ...baseSchemaCreatedAt },
11+
{ ...baseSchemaUpdatedAt },
1012
{
1113
type: "string",
1214
name: 'name',

ving/schema/schemas/CronJob.mjs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import { baseSchemaProps, dbVarChar, zodString, dbBoolean, dbText, dbJson, zodJsonObject } from '../helpers.mjs';
1+
import { baseSchemaId, baseSchemaCreatedAt, baseSchemaUpdatedAt, dbVarChar, zodString, dbBoolean, dbText, dbJson, zodJsonObject } from '../helpers.mjs';
22

33
export const cronJobSchema = {
44
kind: 'CronJob',
55
tableName: 'cronjobs',
66
owner: ['admin'],
77
props: [
8-
...baseSchemaProps,
8+
{ ...baseSchemaId },
9+
{ ...baseSchemaCreatedAt },
10+
{ ...baseSchemaUpdatedAt },
911
{
1012
type: "string",
1113
name: "schedule",

ving/schema/schemas/S3File.mjs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import { baseSchemaProps, dbVarChar, zodString, dbEnum, dbBoolean, dbText, dbRelation, dbDateTime, dbTimestamp, dbInt, dbJson, zodNumber, zodJsonObject } from '../helpers.mjs';
1+
import { baseSchemaId, baseSchemaCreatedAt, baseSchemaUpdatedAt, dbVarChar, zodString, dbEnum, dbBoolean, dbText, dbRelation, dbDateTime, dbTimestamp, dbInt, dbJson, zodNumber, zodJsonObject } from '../helpers.mjs';
22

33
export const s3fileSchema = {
44
kind: 'S3File',
55
tableName: 's3files',
66
owner: ['$userId', 'admin'],
77
props: [
8-
...baseSchemaProps,
8+
{ ...baseSchemaId },
9+
{ ...baseSchemaCreatedAt },
10+
{ ...baseSchemaUpdatedAt },
911
{
1012
type: "string",
1113
name: "filename",

ving/schema/schemas/User.mjs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import { baseSchemaProps, dbVarChar, zodString, dbEnum, dbBoolean, dbRelation, dbMediumText } from '../helpers.mjs';
1+
import { baseSchemaId, baseSchemaCreatedAt, baseSchemaUpdatedAt, dbVarChar, zodString, dbEnum, dbBoolean, dbRelation, dbMediumText } from '../helpers.mjs';
22

33
export const userSchema = {
44
kind: 'User',
55
tableName: 'users',
66
owner: ['$id', 'admin'],
77
props: [
8-
...baseSchemaProps,
8+
{ ...baseSchemaId },
9+
{ ...baseSchemaCreatedAt },
10+
{ ...baseSchemaUpdatedAt },
911
{
1012
type: "string",
1113
name: "username",

0 commit comments

Comments
 (0)