idora.js-prisma 0.0.0-stage → 1.1.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.
- package/LICENSE +21 -0
- package/README.md +107 -2
- package/dist/index.d.ts +82 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +163 -0
- package/dist/index.js.map +1 -0
- package/package.json +60 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jake Seracino
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,108 @@
|
|
|
1
|
-
#
|
|
1
|
+
# idora.js-prisma
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A [Prisma Client extension](https://www.prisma.io/docs/orm/prisma-client/client-extensions) that
|
|
4
|
+
gives new rows [Idora](https://github.com/SrKleRAimBot/Idora/tree/main/Idora.JS) identifiers such
|
|
5
|
+
as `usr_01k2f9v8ta7m3x0qbrn4dzeh5c`.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { idoraExtension } from 'idora.js-prisma';
|
|
9
|
+
import { PrismaClient } from './generated/prisma/client.js';
|
|
10
|
+
|
|
11
|
+
export const prisma = new PrismaClient({ adapter }).$extends(
|
|
12
|
+
idoraExtension({
|
|
13
|
+
ids,
|
|
14
|
+
models: {
|
|
15
|
+
user: User, // the prefix User is registered with
|
|
16
|
+
auditLog: 'aud', // or a prefix of its own
|
|
17
|
+
},
|
|
18
|
+
}),
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
const user = await prisma.user.create({ data: { email } });
|
|
22
|
+
user.id; // 'usr_01k2f9v8ta7m3x0qbrn4dzeh5c'
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Prisma's `@default` cannot call your code, so a prefixed, time-ordered key otherwise means
|
|
26
|
+
remembering `id: ids.generate(User)` at every create. This puts it in one place.
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Install
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm install idora.js-prisma idora.js @prisma/client
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`idora.js` and `@prisma/client` (6.4 or later, or 7) are peer dependencies, and this package adds no others. It
|
|
37
|
+
is an ES module with TypeScript declarations included.
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## The schema
|
|
42
|
+
|
|
43
|
+
The identifier is generated in your process, before the query is sent, but the field still needs
|
|
44
|
+
`@default(dbgenerated())`:
|
|
45
|
+
|
|
46
|
+
```prisma
|
|
47
|
+
model User {
|
|
48
|
+
id String @id @default(dbgenerated()) @db.VarChar(30)
|
|
49
|
+
email String @unique
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Prisma's generated types make a field optional in `create`, `createMany` and `upsert` only when
|
|
54
|
+
it has a `@default`. Without one, `prisma.user.create({ data: { email } })` does not compile:
|
|
55
|
+
`UserCreateInput` requires `id`, and the extension never gets the chance to fill it in.
|
|
56
|
+
`dbgenerated()` with no argument is the default that says "the value comes from elsewhere": it
|
|
57
|
+
makes `id` optional in the client's types and puts no `DEFAULT` on the column. Prisma Migrate
|
|
58
|
+
emits exactly the DDL it would for a plain `String @id` on PostgreSQL, MySQL and SQLite, so a
|
|
59
|
+
create that somehow bypasses the extension fails on the `NOT NULL` key instead of storing a value
|
|
60
|
+
you did not choose.
|
|
61
|
+
|
|
62
|
+
The package's own tests generate a client from this schema and type-check these calls against it.
|
|
63
|
+
|
|
64
|
+
Every identifier for one entity type has the same length — the prefix, the separator, and a
|
|
65
|
+
26-character ULID or 32-character UUIDv7 — so `@db.VarChar(30)` suits a three-letter prefix with
|
|
66
|
+
ULIDs, on PostgreSQL and MySQL.
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Models
|
|
71
|
+
|
|
72
|
+
`models` maps each model that gets identifiers to where they come from. Models not listed are left
|
|
73
|
+
alone. A model may be named as the client spells it (`auditLog`) or as the schema does (`AuditLog`).
|
|
74
|
+
|
|
75
|
+
| Value | Identifiers |
|
|
76
|
+
| --- | --- |
|
|
77
|
+
| `User` | `ids.generate(User)`: the prefix the entity type is registered with |
|
|
78
|
+
| `'aud'` | `ids.generateWithPrefix('aud')`: for models with no class of their own to register, which in a Prisma project is most of them |
|
|
79
|
+
| `{ entity: User, field: 'publicId' }` | the same, in a field other than `id` |
|
|
80
|
+
| `{ prefix: 'ses', field: 'token' }` | the same, in a field other than `id` |
|
|
81
|
+
|
|
82
|
+
Everything is checked when the extension is created: an unregistered entity type throws
|
|
83
|
+
`EntityPrefixNotRegisteredError` and an invalid prefix `InvalidEntityPrefixError`, so a mistake
|
|
84
|
+
stops start-up rather than the first insert.
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## What is filled in
|
|
89
|
+
|
|
90
|
+
| Operation | Filled in |
|
|
91
|
+
| --- | --- |
|
|
92
|
+
| `create` | `data` |
|
|
93
|
+
| `createMany`, `createManyAndReturn` | every record in `data` |
|
|
94
|
+
| `upsert` | `create` — `update` is left alone |
|
|
95
|
+
|
|
96
|
+
Only a field that is missing — `undefined`, or `Prisma.skip` with `strictUndefinedChecks`, as in
|
|
97
|
+
`id: suppliedId ?? Prisma.skip` — is filled. An identifier the query supplies is kept, and the
|
|
98
|
+
arguments you pass are never modified: the query receives a copy.
|
|
99
|
+
|
|
100
|
+
Prisma does not run query extensions for records created by a **nested write**, such as
|
|
101
|
+
`posts: { create: [...] }` inside a `user.create`. Give those an identifier yourself, with
|
|
102
|
+
`ids.generate(Post)`.
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## License
|
|
107
|
+
|
|
108
|
+
MIT — see [LICENSE](https://github.com/SrKleRAimBot/Idora/blob/main/LICENSE).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* idora.js-prisma — a Prisma Client extension that gives new rows Idora identifiers such as
|
|
3
|
+
* `usr_01k2f9v8ta7m3x0qbrn4dzeh5c`.
|
|
4
|
+
*
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
*/
|
|
7
|
+
import { type EntityType, Idora } from 'idora.js';
|
|
8
|
+
/**
|
|
9
|
+
* Where a model's identifiers come from:
|
|
10
|
+
*
|
|
11
|
+
* - an entity type registered with the generator, as in `user: User`;
|
|
12
|
+
* - a prefix, as in `auditLog: 'aud'` — for the many Prisma projects whose models have no class
|
|
13
|
+
* of their own to register;
|
|
14
|
+
* - either of those with a `field` other than `id`, as in `session: { prefix: 'ses', field: 'token' }`.
|
|
15
|
+
*/
|
|
16
|
+
export type ModelIdSource = EntityType | string | {
|
|
17
|
+
readonly entity: EntityType;
|
|
18
|
+
readonly prefix?: undefined;
|
|
19
|
+
readonly field?: string;
|
|
20
|
+
} | {
|
|
21
|
+
readonly prefix: string;
|
|
22
|
+
readonly entity?: undefined;
|
|
23
|
+
readonly field?: string;
|
|
24
|
+
};
|
|
25
|
+
/** Configuration for {@link idoraExtension}. Read once, when the extension is created. */
|
|
26
|
+
export interface IdoraExtensionOptions {
|
|
27
|
+
/** The generator that mints the identifiers, and with which any entity types are registered. */
|
|
28
|
+
readonly ids: Idora;
|
|
29
|
+
/**
|
|
30
|
+
* The models that get identifiers, keyed by name — either as the client spells it (`user`,
|
|
31
|
+
* `auditLog`) or as the schema does (`User`, `AuditLog`). Models not listed are left alone.
|
|
32
|
+
*/
|
|
33
|
+
readonly models: Readonly<Record<string, ModelIdSource>>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A Prisma Client extension that fills in a model's identifier whenever a create leaves it out:
|
|
37
|
+
*
|
|
38
|
+
* ```ts
|
|
39
|
+
* import { PrismaClient } from './generated/prisma/client.js';
|
|
40
|
+
* import { idoraExtension } from 'idora.js-prisma';
|
|
41
|
+
*
|
|
42
|
+
* export const prisma = new PrismaClient({ adapter }).$extends(
|
|
43
|
+
* idoraExtension({
|
|
44
|
+
* ids,
|
|
45
|
+
* models: {
|
|
46
|
+
* user: User, // the prefix User is registered with
|
|
47
|
+
* auditLog: 'aud', // or a prefix of its own
|
|
48
|
+
* },
|
|
49
|
+
* }),
|
|
50
|
+
* );
|
|
51
|
+
*
|
|
52
|
+
* const user = await prisma.user.create({ data: { email } });
|
|
53
|
+
* user.id; // 'usr_01k2f9v8ta7m3x0qbrn4dzeh5c'
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* In the schema, mark the field `@default(dbgenerated())`. The identifier is generated in your
|
|
57
|
+
* process, before the query is sent, but without a `@default` Prisma's generated types require
|
|
58
|
+
* `id` in every create. `dbgenerated()` with no argument makes it optional there and adds no
|
|
59
|
+
* `DEFAULT` to the column, so a create that bypasses the extension fails on the NOT NULL key
|
|
60
|
+
* rather than storing something else.
|
|
61
|
+
*
|
|
62
|
+
* ```prisma
|
|
63
|
+
* model User {
|
|
64
|
+
* id String @id @default(dbgenerated()) @db.VarChar(30)
|
|
65
|
+
* email String @unique
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* `create`, `createMany`, `createManyAndReturn` and the create half of `upsert` are covered. An
|
|
70
|
+
* identifier the query already supplies is kept. Prisma does not run query extensions for the
|
|
71
|
+
* records a nested write creates — `posts: { create: [...] }` inside a `user.create` — so give
|
|
72
|
+
* those an identifier yourself, with `ids.generate(Post)`.
|
|
73
|
+
*
|
|
74
|
+
* The arguments you pass are never modified; the query receives a copy with the identifiers added.
|
|
75
|
+
*
|
|
76
|
+
* @throws {EntityPrefixNotRegisteredError} A model names an entity type that is not registered with
|
|
77
|
+
* `ids`. Thrown when the extension is created, so the mistake stops start-up.
|
|
78
|
+
* @throws {InvalidEntityPrefixError} A model names a prefix that is not valid.
|
|
79
|
+
* @throws {TypeError} The options have the wrong shape, or two keys name the same model.
|
|
80
|
+
*/
|
|
81
|
+
export declare function idoraExtension(options: IdoraExtensionOptions): (client: any) => import("@prisma/client/extension").PrismaClientExtends<import("@prisma/client/runtime/client").InternalArgs<{}, {}, {}, {}>>;
|
|
82
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAElD;;;;;;;GAOG;AACH,MAAM,MAAM,aAAa,GACrB,UAAU,GACV,MAAM,GACN;IAAE,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GACrF;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEtF,0FAA0F;AAC1F,MAAM,WAAW,qBAAqB;IACpC,gGAAgG;IAChG,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC;IAEpB;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC;CAC1D;AAQD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,qBAAqB,iJA2B5D"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* idora.js-prisma — a Prisma Client extension that gives new rows Idora identifiers such as
|
|
3
|
+
* `usr_01k2f9v8ta7m3x0qbrn4dzeh5c`.
|
|
4
|
+
*
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
*/
|
|
7
|
+
import { Prisma } from '@prisma/client/extension';
|
|
8
|
+
import { Idora } from 'idora.js';
|
|
9
|
+
/**
|
|
10
|
+
* A Prisma Client extension that fills in a model's identifier whenever a create leaves it out:
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { PrismaClient } from './generated/prisma/client.js';
|
|
14
|
+
* import { idoraExtension } from 'idora.js-prisma';
|
|
15
|
+
*
|
|
16
|
+
* export const prisma = new PrismaClient({ adapter }).$extends(
|
|
17
|
+
* idoraExtension({
|
|
18
|
+
* ids,
|
|
19
|
+
* models: {
|
|
20
|
+
* user: User, // the prefix User is registered with
|
|
21
|
+
* auditLog: 'aud', // or a prefix of its own
|
|
22
|
+
* },
|
|
23
|
+
* }),
|
|
24
|
+
* );
|
|
25
|
+
*
|
|
26
|
+
* const user = await prisma.user.create({ data: { email } });
|
|
27
|
+
* user.id; // 'usr_01k2f9v8ta7m3x0qbrn4dzeh5c'
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* In the schema, mark the field `@default(dbgenerated())`. The identifier is generated in your
|
|
31
|
+
* process, before the query is sent, but without a `@default` Prisma's generated types require
|
|
32
|
+
* `id` in every create. `dbgenerated()` with no argument makes it optional there and adds no
|
|
33
|
+
* `DEFAULT` to the column, so a create that bypasses the extension fails on the NOT NULL key
|
|
34
|
+
* rather than storing something else.
|
|
35
|
+
*
|
|
36
|
+
* ```prisma
|
|
37
|
+
* model User {
|
|
38
|
+
* id String @id @default(dbgenerated()) @db.VarChar(30)
|
|
39
|
+
* email String @unique
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* `create`, `createMany`, `createManyAndReturn` and the create half of `upsert` are covered. An
|
|
44
|
+
* identifier the query already supplies is kept. Prisma does not run query extensions for the
|
|
45
|
+
* records a nested write creates — `posts: { create: [...] }` inside a `user.create` — so give
|
|
46
|
+
* those an identifier yourself, with `ids.generate(Post)`.
|
|
47
|
+
*
|
|
48
|
+
* The arguments you pass are never modified; the query receives a copy with the identifiers added.
|
|
49
|
+
*
|
|
50
|
+
* @throws {EntityPrefixNotRegisteredError} A model names an entity type that is not registered with
|
|
51
|
+
* `ids`. Thrown when the extension is created, so the mistake stops start-up.
|
|
52
|
+
* @throws {InvalidEntityPrefixError} A model names a prefix that is not valid.
|
|
53
|
+
* @throws {TypeError} The options have the wrong shape, or two keys name the same model.
|
|
54
|
+
*/
|
|
55
|
+
export function idoraExtension(options) {
|
|
56
|
+
const models = resolveModels(options);
|
|
57
|
+
const lookup = (model) => models.get(clientName(model));
|
|
58
|
+
return Prisma.defineExtension({
|
|
59
|
+
name: 'idora',
|
|
60
|
+
query: {
|
|
61
|
+
$allModels: {
|
|
62
|
+
create({ model, args, query }) {
|
|
63
|
+
const ids = lookup(model);
|
|
64
|
+
return query(ids === undefined ? args : { ...args, data: fillOne(ids, args['data']) });
|
|
65
|
+
},
|
|
66
|
+
createMany({ model, args, query }) {
|
|
67
|
+
const ids = lookup(model);
|
|
68
|
+
return query(ids === undefined ? args : { ...args, data: fillMany(ids, args['data']) });
|
|
69
|
+
},
|
|
70
|
+
createManyAndReturn({ model, args, query }) {
|
|
71
|
+
const ids = lookup(model);
|
|
72
|
+
return query(ids === undefined ? args : { ...args, data: fillMany(ids, args['data']) });
|
|
73
|
+
},
|
|
74
|
+
upsert({ model, args, query }) {
|
|
75
|
+
const ids = lookup(model);
|
|
76
|
+
return query(ids === undefined ? args : { ...args, create: fillOne(ids, args['create']) });
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/** Checks the configuration and works out, for each model, which field to fill and how. */
|
|
83
|
+
function resolveModels(options) {
|
|
84
|
+
if (options === null || typeof options !== 'object') {
|
|
85
|
+
throw new TypeError(`idoraExtension needs an options object, as in idoraExtension({ ids, models: { user: User } }).`);
|
|
86
|
+
}
|
|
87
|
+
const { ids, models } = options;
|
|
88
|
+
if (!(ids instanceof Idora)) {
|
|
89
|
+
throw new TypeError(`idoraExtension needs the Idora generator as 'ids', as in idoraExtension({ ids, models: { user: User } }).`);
|
|
90
|
+
}
|
|
91
|
+
if (models === null || typeof models !== 'object') {
|
|
92
|
+
throw new TypeError(`idoraExtension needs 'models', mapping model names to entity types or prefixes, as in { user: User }.`);
|
|
93
|
+
}
|
|
94
|
+
const resolved = new Map();
|
|
95
|
+
for (const [key, source] of Object.entries(models)) {
|
|
96
|
+
const name = clientName(key);
|
|
97
|
+
if (resolved.has(name)) {
|
|
98
|
+
throw new TypeError(`The models '${key}' and '${name}' given to idoraExtension are the same model. List each model once.`);
|
|
99
|
+
}
|
|
100
|
+
resolved.set(name, resolveModel(ids, key, source));
|
|
101
|
+
}
|
|
102
|
+
return resolved;
|
|
103
|
+
}
|
|
104
|
+
function resolveModel(ids, key, source) {
|
|
105
|
+
const { entity, prefix, field = 'id' } = typeof source === 'function' ? { entity: source } : typeof source === 'string' ? { prefix: source } : (source ?? {});
|
|
106
|
+
if (typeof field !== 'string' || field === '') {
|
|
107
|
+
throw new TypeError(`The field given for the model '${key}' must be the name of a field, such as 'id'.`);
|
|
108
|
+
}
|
|
109
|
+
if (entity !== undefined) {
|
|
110
|
+
if (prefix !== undefined) {
|
|
111
|
+
throw new TypeError(`The model '${key}' was given both an entity and a prefix. Give one: the entity's registered prefix is used when you name the entity.`);
|
|
112
|
+
}
|
|
113
|
+
// Throws now, for an unregistered entity, rather than on the first insert.
|
|
114
|
+
ids.registry.getPrefix(entity);
|
|
115
|
+
return { field, generate: () => ids.generate(entity) };
|
|
116
|
+
}
|
|
117
|
+
if (prefix === undefined) {
|
|
118
|
+
throw new TypeError(`The model '${key}' needs an entity type registered with the generator, or a prefix, as in { ${key}: User } or { ${key}: 'usr' }.`);
|
|
119
|
+
}
|
|
120
|
+
// Generating one identifier validates the prefix exactly as every later call will, so a typo
|
|
121
|
+
// stops start-up rather than the first insert.
|
|
122
|
+
ids.generateWithPrefix(prefix);
|
|
123
|
+
return { field, generate: () => ids.generateWithPrefix(prefix) };
|
|
124
|
+
}
|
|
125
|
+
/** A copy of one record's data with the identifier filled in, if it was missing. */
|
|
126
|
+
function fillOne(ids, data) {
|
|
127
|
+
if (data === null || typeof data !== 'object' || Array.isArray(data)) {
|
|
128
|
+
// Not something this extension understands; let Prisma report it.
|
|
129
|
+
return data;
|
|
130
|
+
}
|
|
131
|
+
const record = data;
|
|
132
|
+
const supplied = record[ids.field];
|
|
133
|
+
return supplied === undefined || isPrismaSkip(supplied) ? { ...record, [ids.field]: ids.generate() } : data;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Whether `value` is `Prisma.skip`, the marker `strictUndefinedChecks` uses to leave a field out,
|
|
137
|
+
* as in `id: suppliedId ?? Prisma.skip`. Passed through, it would send the create with no key at
|
|
138
|
+
* all, which the `@default(dbgenerated())` column cannot fill, so it counts as missing.
|
|
139
|
+
*
|
|
140
|
+
* Recognised by what it does rather than by identity: its class name is minified, and Prisma 6
|
|
141
|
+
* ships a separate instance in each runtime, so the one a generated client uses need not be the
|
|
142
|
+
* one this package could import. `skip.ifUndefined(undefined)` returns `skip` itself, and no
|
|
143
|
+
* identifier, a string, has that method.
|
|
144
|
+
*/
|
|
145
|
+
function isPrismaSkip(value) {
|
|
146
|
+
if (value === null || typeof value !== 'object') {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
const ifUndefined = value.ifUndefined;
|
|
150
|
+
return typeof ifUndefined === 'function' && ifUndefined.call(value, undefined) === value;
|
|
151
|
+
}
|
|
152
|
+
/** {@link fillOne} for `createMany`, whose `data` may be one record or a list of them. */
|
|
153
|
+
function fillMany(ids, data) {
|
|
154
|
+
return Array.isArray(data) ? data.map((record) => fillOne(ids, record)) : fillOne(ids, data);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* The name a model goes by on the client: the schema's name with its first letter lowercased, so
|
|
158
|
+
* `AuditLog` and `auditLog` are the same model. Query hooks are told the schema's name.
|
|
159
|
+
*/
|
|
160
|
+
function clientName(model) {
|
|
161
|
+
return model.charAt(0).toLowerCase() + model.slice(1);
|
|
162
|
+
}
|
|
163
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAmB,KAAK,EAAE,MAAM,UAAU,CAAC;AAkClD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,MAAM,UAAU,cAAc,CAAC,OAA8B;IAC3D,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,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;AAC/G,CAAC;AAED;;;GAGG;AACH,SAAS,UAAU,CAAC,KAAa;IAC/B,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACxD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,62 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "idora.js-prisma",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "A Prisma Client extension that gives new rows Idora identifiers such as usr_01k2f9v8ta7m3x0qbrn4dzeh5c: create, createMany, createManyAndReturn and upsert fill in a missing id from the model's registered prefix.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"idora",
|
|
7
|
+
"prisma",
|
|
8
|
+
"prisma-extension",
|
|
9
|
+
"id",
|
|
10
|
+
"identifier",
|
|
11
|
+
"ulid",
|
|
12
|
+
"uuidv7",
|
|
13
|
+
"prefixed-id",
|
|
14
|
+
"primary-key"
|
|
15
|
+
],
|
|
16
|
+
"homepage": "https://github.com/SrKleRAimBot/Idora/tree/main/Idora.JS/extensions/prisma#readme",
|
|
17
|
+
"bugs": "https://github.com/SrKleRAimBot/Idora/issues",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/SrKleRAimBot/Idora.git",
|
|
21
|
+
"directory": "Idora.JS/extensions/prisma"
|
|
22
|
+
},
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"author": "Jake Seracino",
|
|
25
|
+
"type": "module",
|
|
26
|
+
"sideEffects": false,
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"default": "./dist/index.js"
|
|
31
|
+
},
|
|
32
|
+
"./package.json": "./package.json"
|
|
33
|
+
},
|
|
34
|
+
"main": "./dist/index.js",
|
|
35
|
+
"types": "./dist/index.d.ts",
|
|
36
|
+
"files": [
|
|
37
|
+
"dist",
|
|
38
|
+
"!dist/**/*.tsbuildinfo"
|
|
39
|
+
],
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=20"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "tsc -p tsconfig.json",
|
|
45
|
+
"generate:test": "prisma generate --schema test/fixtures/schema.prisma",
|
|
46
|
+
"build:test": "npm run generate:test && tsc -p tsconfig.test.json",
|
|
47
|
+
"typecheck": "npm run generate:test && tsc -p tsconfig.test.json --noEmit",
|
|
48
|
+
"test": "npm run build:test && node --test build/test/*.test.js",
|
|
49
|
+
"prepack": "npm run build"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"@prisma/client": "^6.4.0 || ^7.0.0",
|
|
53
|
+
"idora.js": "^1.1.0"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@prisma/client": "7.10.1",
|
|
57
|
+
"@types/node": "22.20.5",
|
|
58
|
+
"idora.js": "file:../..",
|
|
59
|
+
"prisma": "7.10.1",
|
|
60
|
+
"typescript": "7.0.2"
|
|
61
|
+
}
|
|
62
|
+
}
|