remult 3.0.6-next.0 → 3.0.6
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/esm/graphql.js +3 -3
- package/esm/index.js +7 -1
- package/esm/remult-d1-http.js +32 -0
- package/esm/remult-d1.js +90 -0
- package/esm/remult-express.js +4 -1
- package/esm/remult-fastify.js +9 -1
- package/esm/remult-fresh.js +5 -1
- package/esm/remult-hapi.js +7 -6
- package/esm/remult-hono.js +16 -14
- package/esm/remult-next.js +14 -8
- package/esm/remult-nuxt.js +7 -4
- package/esm/remult-solid-start.js +9 -6
- package/esm/remult-sveltekit.js +11 -8
- package/esm/server/index.js +4 -1
- package/esm/server/module.js +1 -1
- package/esm/server/remult-admin.js +9 -5
- package/esm/server/remult-api-server.js +14 -2
- package/esm/server/test-api-data-provider.js +4 -1
- package/esm/src/CompoundIdField.js +1 -0
- package/esm/src/context.js +9 -1
- package/esm/src/remult-static.js +1 -1
- package/esm/src/remult3/RepositoryImplementation.js +37 -21
- package/graphql.js +3 -3
- package/index.d.ts +9 -1
- package/index.js +9 -2
- package/package.json +11 -1
- package/remult-d1-http.d.ts +16 -0
- package/remult-d1-http.js +46 -0
- package/remult-d1.d.ts +27 -0
- package/remult-d1.js +128 -0
- package/remult-express.js +4 -1
- package/remult-fastify.js +6 -1
- package/remult-fresh.js +5 -1
- package/remult-hapi.js +4 -7
- package/remult-hono.js +16 -14
- package/remult-next.js +14 -8
- package/remult-nuxt.js +7 -4
- package/remult-solid-start.js +9 -6
- package/remult-sveltekit.js +11 -8
- package/server/core.d.ts +1 -1
- package/server/index.js +4 -1
- package/server/module.js +1 -1
- package/server/remult-admin.js +9 -5
- package/server/remult-api-server.d.ts +24 -11
- package/server/remult-api-server.js +23 -11
- package/server/test-api-data-provider.js +4 -1
- package/src/CompoundIdField.d.ts +1 -0
- package/src/CompoundIdField.js +1 -0
- package/src/column-interfaces.d.ts +12 -0
- package/src/context.d.ts +15 -2
- package/src/context.js +9 -1
- package/src/entity.d.ts +5 -0
- package/src/remult-static.d.ts +1 -1
- package/src/remult-static.js +1 -1
- package/src/remult3/RepositoryImplementation.d.ts +23 -17
- package/src/remult3/RepositoryImplementation.js +48 -22
- package/src/remult3/remult3.d.ts +8 -2
|
@@ -1191,7 +1191,7 @@ class rowHelperBase {
|
|
|
1191
1191
|
for (const col of this.fieldsMetadata) {
|
|
1192
1192
|
if (this.errors?.[col.key]) {
|
|
1193
1193
|
error.message =
|
|
1194
|
-
this.fields[col.key].metadata.
|
|
1194
|
+
this.fields[col.key].metadata.label +
|
|
1195
1195
|
': ' +
|
|
1196
1196
|
this.errors[col.key];
|
|
1197
1197
|
this.error = error.message;
|
|
@@ -1950,23 +1950,26 @@ export class FieldRefImplementation {
|
|
|
1950
1950
|
return !!!this.error;
|
|
1951
1951
|
}
|
|
1952
1952
|
}
|
|
1953
|
-
let
|
|
1954
|
-
|
|
1953
|
+
let tempLabelTransformer = {
|
|
1954
|
+
transformLabel: (remult, key, label, entityMetaData) => label,
|
|
1955
|
+
set transformCaption(val) {
|
|
1956
|
+
this.transformLabel = val;
|
|
1957
|
+
},
|
|
1955
1958
|
};
|
|
1956
1959
|
export const fieldOptionsEnricher = remultStatic.fieldOptionsEnricher || {
|
|
1957
1960
|
enrichFieldOptions: (options) => options,
|
|
1958
1961
|
};
|
|
1959
|
-
export const
|
|
1960
|
-
(remultStatic.
|
|
1961
|
-
export function
|
|
1962
|
+
export const LabelTransformer = remultStatic.labelTransformer ||
|
|
1963
|
+
(remultStatic.labelTransformer = tempLabelTransformer);
|
|
1964
|
+
export function buildLabel(label, key, remult, metaData) {
|
|
1962
1965
|
let result = undefined;
|
|
1963
|
-
if (typeof
|
|
1966
|
+
if (typeof label === 'function') {
|
|
1964
1967
|
if (remult)
|
|
1965
|
-
result =
|
|
1968
|
+
result = label(remult);
|
|
1966
1969
|
}
|
|
1967
|
-
else if (
|
|
1968
|
-
result =
|
|
1969
|
-
result =
|
|
1970
|
+
else if (label)
|
|
1971
|
+
result = label;
|
|
1972
|
+
result = LabelTransformer.transformLabel(remult, key, result ?? '', metaData);
|
|
1970
1973
|
if (result)
|
|
1971
1974
|
return result;
|
|
1972
1975
|
if (key)
|
|
@@ -1994,7 +1997,7 @@ export class columnDefsImpl {
|
|
|
1994
1997
|
catch (err) {
|
|
1995
1998
|
const error = `${String(prop)} failed for value ${args?.[0]}. Error: ${typeof err === 'string' ? err : err.message}`;
|
|
1996
1999
|
throw new EntityError({
|
|
1997
|
-
message: this.
|
|
2000
|
+
message: this.label + ': ' + error,
|
|
1998
2001
|
modelState: {
|
|
1999
2002
|
[this.key]: error,
|
|
2000
2003
|
},
|
|
@@ -2018,7 +2021,7 @@ export class columnDefsImpl {
|
|
|
2018
2021
|
this.dbName = settings.dbName;
|
|
2019
2022
|
if (this.dbName == undefined)
|
|
2020
2023
|
this.dbName = settings.key;
|
|
2021
|
-
this.
|
|
2024
|
+
this.label = buildLabel(settings.label ?? settings.caption, settings.key, remult, entityDefs);
|
|
2022
2025
|
}
|
|
2023
2026
|
apiUpdateAllowed(item) {
|
|
2024
2027
|
if (this.options.allowApiUpdate === undefined)
|
|
@@ -2049,7 +2052,10 @@ export class columnDefsImpl {
|
|
|
2049
2052
|
readonly = false;
|
|
2050
2053
|
valueConverter;
|
|
2051
2054
|
allowNull;
|
|
2052
|
-
|
|
2055
|
+
label;
|
|
2056
|
+
get caption() {
|
|
2057
|
+
return this.label;
|
|
2058
|
+
}
|
|
2053
2059
|
dbName;
|
|
2054
2060
|
inputType;
|
|
2055
2061
|
key;
|
|
@@ -2103,7 +2109,7 @@ class EntityFullInfo {
|
|
|
2103
2109
|
this.fieldsMetadata.push((r[x.key] = new columnDefsImpl(x, this, remult)));
|
|
2104
2110
|
}
|
|
2105
2111
|
this.fields = r;
|
|
2106
|
-
this.
|
|
2112
|
+
this.label = buildLabel(entityInfo.label ?? entityInfo.caption, this.key, remult, this);
|
|
2107
2113
|
if (entityInfo.id) {
|
|
2108
2114
|
let r = typeof entityInfo.id === 'string'
|
|
2109
2115
|
? this.fields.find(entityInfo.id)
|
|
@@ -2218,7 +2224,10 @@ class EntityFullInfo {
|
|
|
2218
2224
|
};
|
|
2219
2225
|
fields;
|
|
2220
2226
|
dbName;
|
|
2221
|
-
|
|
2227
|
+
label;
|
|
2228
|
+
get caption() {
|
|
2229
|
+
return this.label;
|
|
2230
|
+
}
|
|
2222
2231
|
}
|
|
2223
2232
|
export function FieldType(...options) {
|
|
2224
2233
|
return (target, context) => {
|
|
@@ -2238,7 +2247,7 @@ export function ValueListFieldType(...options) {
|
|
|
2238
2247
|
FieldType((o) => {
|
|
2239
2248
|
;
|
|
2240
2249
|
(o.valueConverter = ValueListInfo.get(type)),
|
|
2241
|
-
(o.displayValue = (item, val) => val?.caption);
|
|
2250
|
+
(o.displayValue = (item, val) => val?.label ?? val?.caption);
|
|
2242
2251
|
o.validate = (entity, ref) => {
|
|
2243
2252
|
const values = ValueListInfo.get(type).getValues();
|
|
2244
2253
|
if (ref.value && !values.find((v) => v === ref.value)) {
|
|
@@ -2271,8 +2280,7 @@ export class ValueListInfo {
|
|
|
2271
2280
|
s.id = member;
|
|
2272
2281
|
if (typeof s.id === 'number')
|
|
2273
2282
|
this.isNumeric = true;
|
|
2274
|
-
|
|
2275
|
-
s.caption = makeTitle(s.id !== undefined ? s.id.toString() : member);
|
|
2283
|
+
setLabelAndCaption(s, member);
|
|
2276
2284
|
this.byIdMap.set(s.id, s);
|
|
2277
2285
|
this.values.push(s);
|
|
2278
2286
|
}
|
|
@@ -2287,8 +2295,7 @@ export class ValueListInfo {
|
|
|
2287
2295
|
this.values.splice(0, this.values.length, ...op.getValues());
|
|
2288
2296
|
this.byIdMap.clear();
|
|
2289
2297
|
this.values.forEach((s) => {
|
|
2290
|
-
|
|
2291
|
-
s.caption = makeTitle(s.id);
|
|
2298
|
+
setLabelAndCaption(s, '');
|
|
2292
2299
|
this.byIdMap.set(s.id, s);
|
|
2293
2300
|
});
|
|
2294
2301
|
}
|
|
@@ -2337,6 +2344,15 @@ export class ValueListInfo {
|
|
|
2337
2344
|
inputType;
|
|
2338
2345
|
}
|
|
2339
2346
|
const typeCache = new Map();
|
|
2347
|
+
function setLabelAndCaption(s, member) {
|
|
2348
|
+
let label = s.label ?? s.caption;
|
|
2349
|
+
if (label === undefined)
|
|
2350
|
+
label = makeTitle(s.id !== undefined ? s.id.toString() : member);
|
|
2351
|
+
if (s.label === undefined)
|
|
2352
|
+
s.label = label;
|
|
2353
|
+
if (s.caption === undefined)
|
|
2354
|
+
s.caption = label;
|
|
2355
|
+
}
|
|
2340
2356
|
export function getValueList(type) {
|
|
2341
2357
|
let meta = type?.metadata;
|
|
2342
2358
|
if (!meta && isOfType(type, 'options'))
|
package/graphql.js
CHANGED
|
@@ -586,7 +586,7 @@ function remultGraphql(options) {
|
|
|
586
586
|
currentType.fields.push({
|
|
587
587
|
key: f.key,
|
|
588
588
|
value: "".concat(getMetaType(ref)).concat(f.allowNull ? '' : '!'),
|
|
589
|
-
comment: f.
|
|
589
|
+
comment: f.label,
|
|
590
590
|
});
|
|
591
591
|
currentType.query.resultProcessors.push(function (r, orig) {
|
|
592
592
|
r[f.key] = function (args, req, gqlInfo) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
@@ -661,7 +661,7 @@ function remultGraphql(options) {
|
|
|
661
661
|
currentType.fields.push({
|
|
662
662
|
key: f.key,
|
|
663
663
|
value: "".concat(getMetaType(ref)).concat(f.allowNull ? '' : '!'),
|
|
664
|
-
comment: f.
|
|
664
|
+
comment: f.label,
|
|
665
665
|
});
|
|
666
666
|
var refKey_1 = ref.key;
|
|
667
667
|
currentType.query.resultProcessors.push(function (r) {
|
|
@@ -713,7 +713,7 @@ function remultGraphql(options) {
|
|
|
713
713
|
currentType.fields.push({
|
|
714
714
|
key: f.key,
|
|
715
715
|
value: "".concat(type).concat(f.allowNull ? '' : '!'),
|
|
716
|
-
comment: f.
|
|
716
|
+
comment: f.label,
|
|
717
717
|
});
|
|
718
718
|
}
|
|
719
719
|
// sorting
|
package/index.d.ts
CHANGED
|
@@ -4,7 +4,15 @@ export { ArrayEntityDataProvider } from './src/data-providers/array-entity-data-
|
|
|
4
4
|
export type { ClassType } from './classType.js';
|
|
5
5
|
export { ValidateFieldEvent, MembersOnly, NumericKeys, FieldsMetadata, FieldRef, IdFieldRef, FieldsRef, EntityMetadata, EntityOrderBy, EntityFilter, FindOptions, FindOptionsBase, QueryResult, QueryOptions, UpsertOptions, Repository, GroupByOptions, GroupByResult, FindFirstOptions, ComparisonValueFilter, ValueFilter, IdFilter, ContainsStringValueFilter, EntityRef, SortSegments, Paginator, LiveQuery, LiveQueryChangeInfo, Subscribable, RefSubscriber, RefSubscriberBase, RelationOptions, ObjectMembersOnly, MembersToInclude, RepositoryRelations, EntityIdFields, ClassFieldDecorator, ClassFieldDecoratorContextStub, //n1 consider removing in ts5
|
|
6
6
|
LifecycleEvent, FieldsRefBase, FieldsRefForEntityBase, RepositoryRelationsForEntityBase, ControllerRefForControllerBase, ControllerRefBase, ControllerRef, EntityRefForEntityBase, IdMetadata, FindFirstOptionsBase, } from './src/remult3/remult3.js';
|
|
7
|
-
export { EntityBase, ControllerBase, FieldType, getFields, ValueListFieldType, getValueList, ValueListFieldOptions, ValueListInfo,
|
|
7
|
+
export { EntityBase, ControllerBase, FieldType, getFields, ValueListFieldType, getValueList, ValueListFieldOptions, ValueListInfo, } from './src/remult3/RepositoryImplementation.js';
|
|
8
|
+
export { LabelTransformer } from './src/remult3/RepositoryImplementation.js';
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated use `LabelTransformer` instead
|
|
11
|
+
*/
|
|
12
|
+
export declare const CaptionTransformer: {
|
|
13
|
+
transformLabel: (remult: import("./src/context.js").Remult, key: string, label: string, entityMetaData: import("./src/remult3/remult3.js").EntityMetadata<any>) => string;
|
|
14
|
+
transformCaption: (remult: import("./src/context.js").Remult, key: string, label: string, entityMetaData: import("./src/remult3/remult3.js").EntityMetadata<any>) => string;
|
|
15
|
+
};
|
|
8
16
|
export { Entity } from './src/remult3/entity.js';
|
|
9
17
|
export { getEntityRef } from './src/remult3/getEntityRef.js';
|
|
10
18
|
export { Field, Fields, StringFieldOptions, Relations, } from './src/remult3/Fields.js';
|
package/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.InMemoryLiveQueryStorage = exports.remult = exports.ValueConverters = exports.createValueValidator = exports.createValueValidatorWithArgs = exports.createValidatorWithArgs = exports.createValidator = exports.valueValidator = exports.Validators = exports.UrlBuilder = exports.Filter = exports.CompoundIdField = exports.Sort = exports.EventSource = exports.isBackend = exports.withRemult = exports.Remult = exports.Allow = exports.ForbiddenError = exports.ProgressListener = exports.BackendMethod = exports.Controller = exports.JsonEntityIndexedDbStorage = exports.JsonEntityOpfsStorage = exports.JsonDataProvider = exports.dbNamesOf = exports.CustomSqlFilterBuilder = exports.SqlDatabase = exports.InMemoryDataProvider = exports.RestDataProvider = exports.EntityError = exports.describeEntity = exports.describeBackendMethods = exports.describeClass = exports.IdEntity = exports.Relations = exports.Fields = exports.Field = exports.getEntityRef = exports.Entity = exports.CaptionTransformer = exports.LabelTransformer = exports.ValueListInfo = exports.getValueList = exports.ValueListFieldType = exports.getFields = exports.FieldType = exports.ControllerBase = exports.EntityBase = exports.ArrayEntityDataProvider = void 0;
|
|
4
|
+
exports.SubscriptionChannel = void 0;
|
|
4
5
|
exports.repo = repo;
|
|
5
6
|
var array_entity_data_provider_js_1 = require("./src/data-providers/array-entity-data-provider.js");
|
|
6
7
|
Object.defineProperty(exports, "ArrayEntityDataProvider", { enumerable: true, get: function () { return array_entity_data_provider_js_1.ArrayEntityDataProvider; } });
|
|
@@ -12,7 +13,13 @@ Object.defineProperty(exports, "getFields", { enumerable: true, get: function ()
|
|
|
12
13
|
Object.defineProperty(exports, "ValueListFieldType", { enumerable: true, get: function () { return RepositoryImplementation_js_1.ValueListFieldType; } });
|
|
13
14
|
Object.defineProperty(exports, "getValueList", { enumerable: true, get: function () { return RepositoryImplementation_js_1.getValueList; } });
|
|
14
15
|
Object.defineProperty(exports, "ValueListInfo", { enumerable: true, get: function () { return RepositoryImplementation_js_1.ValueListInfo; } });
|
|
15
|
-
|
|
16
|
+
var RepositoryImplementation_js_2 = require("./src/remult3/RepositoryImplementation.js");
|
|
17
|
+
var RepositoryImplementation_js_3 = require("./src/remult3/RepositoryImplementation.js");
|
|
18
|
+
Object.defineProperty(exports, "LabelTransformer", { enumerable: true, get: function () { return RepositoryImplementation_js_3.LabelTransformer; } });
|
|
19
|
+
/**
|
|
20
|
+
* @deprecated use `LabelTransformer` instead
|
|
21
|
+
*/
|
|
22
|
+
exports.CaptionTransformer = RepositoryImplementation_js_2.LabelTransformer;
|
|
16
23
|
var entity_js_1 = require("./src/remult3/entity.js");
|
|
17
24
|
Object.defineProperty(exports, "Entity", { enumerable: true, get: function () { return entity_js_1.Entity; } });
|
|
18
25
|
var getEntityRef_js_1 = require("./src/remult3/getEntityRef.js");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "remult",
|
|
3
|
-
"version": "3.0.6
|
|
3
|
+
"version": "3.0.6",
|
|
4
4
|
"description": "A CRUD framework for full-stack TypeScript",
|
|
5
5
|
"homepage": "https://remult.dev",
|
|
6
6
|
"repository": {
|
|
@@ -131,6 +131,16 @@
|
|
|
131
131
|
"import": "./esm/remult-duckdb.js",
|
|
132
132
|
"types": "./remult-duckdb.d.ts"
|
|
133
133
|
},
|
|
134
|
+
"./remult-d1": {
|
|
135
|
+
"require": "./remult-d1.js",
|
|
136
|
+
"import": "./esm/remult-d1.js",
|
|
137
|
+
"types": "./remult-d1.d.ts"
|
|
138
|
+
},
|
|
139
|
+
"./remult-d1-http": {
|
|
140
|
+
"require": "./remult-d1-http.js",
|
|
141
|
+
"import": "./esm/remult-d1-http.js",
|
|
142
|
+
"types": "./remult-d1-http.d.ts"
|
|
143
|
+
},
|
|
134
144
|
"./remult-bun-sqlite": {
|
|
135
145
|
"require": "./remult-bun-sqlite.js",
|
|
136
146
|
"import": "./esm/remult-bun-sqlite.js",
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { SqlDatabase } from './index.js';
|
|
2
|
+
import { type D1Client, D1DataProvider, type D1RowObject } from './remult-d1.js';
|
|
3
|
+
export { D1DataProvider };
|
|
4
|
+
type D1Credentials = {
|
|
5
|
+
accountId: string;
|
|
6
|
+
apiToken: string;
|
|
7
|
+
databaseId: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function createD1HttpDataProvider(creds: D1Credentials): SqlDatabase;
|
|
10
|
+
export declare class D1HttpClient implements D1Client {
|
|
11
|
+
private d1;
|
|
12
|
+
private accountId;
|
|
13
|
+
private databaseId;
|
|
14
|
+
constructor({ accountId, databaseId, apiToken }: D1Credentials);
|
|
15
|
+
execute(sql: string, params?: unknown[]): Promise<D1RowObject[]>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.D1HttpClient = exports.D1DataProvider = void 0;
|
|
4
|
+
exports.createD1HttpDataProvider = createD1HttpDataProvider;
|
|
5
|
+
var tslib_1 = require("tslib");
|
|
6
|
+
var cloudflare_1 = tslib_1.__importDefault(require("cloudflare"));
|
|
7
|
+
var index_js_1 = require("./index.js");
|
|
8
|
+
var remult_d1_js_1 = require("./remult-d1.js");
|
|
9
|
+
Object.defineProperty(exports, "D1DataProvider", { enumerable: true, get: function () { return remult_d1_js_1.D1DataProvider; } });
|
|
10
|
+
function createD1HttpDataProvider(creds) {
|
|
11
|
+
return new index_js_1.SqlDatabase(new remult_d1_js_1.D1DataProvider(new D1HttpClient(creds)));
|
|
12
|
+
}
|
|
13
|
+
var D1HttpClient = /** @class */ (function () {
|
|
14
|
+
function D1HttpClient(_a) {
|
|
15
|
+
var accountId = _a.accountId, databaseId = _a.databaseId, apiToken = _a.apiToken;
|
|
16
|
+
this.d1 = new cloudflare_1.default({ apiToken: apiToken }).d1.database;
|
|
17
|
+
this.accountId = accountId;
|
|
18
|
+
this.databaseId = databaseId;
|
|
19
|
+
}
|
|
20
|
+
D1HttpClient.prototype.execute = function (sql_1) {
|
|
21
|
+
return tslib_1.__awaiter(this, arguments, void 0, function (sql, params) {
|
|
22
|
+
if (params === void 0) { params = []; }
|
|
23
|
+
return tslib_1.__generator(this, function (_a) {
|
|
24
|
+
return [2 /*return*/, this.d1
|
|
25
|
+
.query(this.databaseId, {
|
|
26
|
+
sql: sql,
|
|
27
|
+
params: params,
|
|
28
|
+
account_id: this.accountId,
|
|
29
|
+
})
|
|
30
|
+
.then(function (_a) {
|
|
31
|
+
var pages = _a.result;
|
|
32
|
+
return pages.flatMap(function (page) { return page.results; });
|
|
33
|
+
})
|
|
34
|
+
// NOTE: d1 query endpoint returns the result as array of object with keys as column names.
|
|
35
|
+
// We're returning that now because the rest of remult seems to expect that.
|
|
36
|
+
// D1 also has a more efficient raw() endpoint that returns {columns: string[], rows: any[][]} that we may want
|
|
37
|
+
// to use eventually, and write code like fromRowToSql()
|
|
38
|
+
// at https://github.com/tursodatabase/libsql-client-ts/blob/main/packages/libsql-client/src/sqlite3.ts#L398
|
|
39
|
+
// to adapt the data
|
|
40
|
+
];
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
return D1HttpClient;
|
|
45
|
+
}());
|
|
46
|
+
exports.D1HttpClient = D1HttpClient;
|
package/remult-d1.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { SqlDatabase, type SqlImplementation } from './index.js';
|
|
2
|
+
import { SqliteCoreDataProvider } from './remult-sqlite-core.js';
|
|
3
|
+
export declare function createD1DataProvider(d1: D1Database): SqlDatabase;
|
|
4
|
+
export declare class D1DataProvider extends SqliteCoreDataProvider {
|
|
5
|
+
private d1;
|
|
6
|
+
/**
|
|
7
|
+
* For production or local d1 using binding
|
|
8
|
+
*
|
|
9
|
+
* const dataProvider = new SqlDatabase(new D1DataProvider(new D1BindingClient(d1)))
|
|
10
|
+
*/
|
|
11
|
+
constructor(d1: D1Client);
|
|
12
|
+
transaction(action: (sql: SqlImplementation) => Promise<void>): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
export type D1RowObject = Record<string, unknown>;
|
|
15
|
+
export interface D1Client {
|
|
16
|
+
execute(sql: string, params?: unknown[]): Promise<D1RowObject[]>;
|
|
17
|
+
}
|
|
18
|
+
export declare class D1BindingClient implements D1Client {
|
|
19
|
+
private d1;
|
|
20
|
+
/**
|
|
21
|
+
* Simple d1 client that wraps the d1 binding directly
|
|
22
|
+
*
|
|
23
|
+
* const d1 = new D1BindingClient(env.DB)
|
|
24
|
+
*/
|
|
25
|
+
constructor(d1: D1Database);
|
|
26
|
+
execute(sql: string, params?: unknown[]): Promise<D1RowObject[]>;
|
|
27
|
+
}
|
package/remult-d1.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/// <reference types="@cloudflare/workers-types" />
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.D1BindingClient = exports.D1DataProvider = void 0;
|
|
5
|
+
exports.createD1DataProvider = createD1DataProvider;
|
|
6
|
+
var tslib_1 = require("tslib");
|
|
7
|
+
var index_js_1 = require("./index.js");
|
|
8
|
+
var remult_sqlite_core_js_1 = require("./remult-sqlite-core.js");
|
|
9
|
+
function createD1DataProvider(d1) {
|
|
10
|
+
return new index_js_1.SqlDatabase(new D1DataProvider(new D1BindingClient(d1)));
|
|
11
|
+
}
|
|
12
|
+
var D1DataProvider = /** @class */ (function (_super) {
|
|
13
|
+
tslib_1.__extends(D1DataProvider, _super);
|
|
14
|
+
/**
|
|
15
|
+
* For production or local d1 using binding
|
|
16
|
+
*
|
|
17
|
+
* const dataProvider = new SqlDatabase(new D1DataProvider(new D1BindingClient(d1)))
|
|
18
|
+
*/
|
|
19
|
+
function D1DataProvider(d1) {
|
|
20
|
+
var _this = _super.call(this, function () { return new D1Command(_this.d1); }, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
21
|
+
return tslib_1.__generator(this, function (_a) {
|
|
22
|
+
return [2 /*return*/];
|
|
23
|
+
});
|
|
24
|
+
}); }) || this;
|
|
25
|
+
_this.d1 = d1;
|
|
26
|
+
return _this;
|
|
27
|
+
}
|
|
28
|
+
D1DataProvider.prototype.transaction = function (action) {
|
|
29
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
30
|
+
return tslib_1.__generator(this, function (_a) {
|
|
31
|
+
switch (_a.label) {
|
|
32
|
+
case 0:
|
|
33
|
+
// As of June 2025, D1 doesn't support transactions
|
|
34
|
+
// Here we simply run the action without wrapping it in a transaction
|
|
35
|
+
// It means queries in action() will be run individually (this is the same decision prisma made)
|
|
36
|
+
return [4 /*yield*/, action(this)];
|
|
37
|
+
case 1:
|
|
38
|
+
// As of June 2025, D1 doesn't support transactions
|
|
39
|
+
// Here we simply run the action without wrapping it in a transaction
|
|
40
|
+
// It means queries in action() will be run individually (this is the same decision prisma made)
|
|
41
|
+
_a.sent();
|
|
42
|
+
return [2 /*return*/];
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
return D1DataProvider;
|
|
48
|
+
}(remult_sqlite_core_js_1.SqliteCoreDataProvider));
|
|
49
|
+
exports.D1DataProvider = D1DataProvider;
|
|
50
|
+
var D1BindingClient = /** @class */ (function () {
|
|
51
|
+
/**
|
|
52
|
+
* Simple d1 client that wraps the d1 binding directly
|
|
53
|
+
*
|
|
54
|
+
* const d1 = new D1BindingClient(env.DB)
|
|
55
|
+
*/
|
|
56
|
+
function D1BindingClient(d1) {
|
|
57
|
+
this.d1 = d1;
|
|
58
|
+
}
|
|
59
|
+
D1BindingClient.prototype.execute = function (sql_1) {
|
|
60
|
+
return tslib_1.__awaiter(this, arguments, void 0, function (sql, params) {
|
|
61
|
+
var results;
|
|
62
|
+
var _a;
|
|
63
|
+
if (params === void 0) { params = []; }
|
|
64
|
+
return tslib_1.__generator(this, function (_b) {
|
|
65
|
+
switch (_b.label) {
|
|
66
|
+
case 0: return [4 /*yield*/, (_a = this.d1
|
|
67
|
+
.prepare(sql))
|
|
68
|
+
.bind.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(params), false)).run()];
|
|
69
|
+
case 1:
|
|
70
|
+
results = (_b.sent()).results;
|
|
71
|
+
return [2 /*return*/, results];
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
return D1BindingClient;
|
|
77
|
+
}());
|
|
78
|
+
exports.D1BindingClient = D1BindingClient;
|
|
79
|
+
var D1Command = /** @class */ (function () {
|
|
80
|
+
function D1Command(d1) {
|
|
81
|
+
this.params = [];
|
|
82
|
+
this.d1 = d1;
|
|
83
|
+
}
|
|
84
|
+
D1Command.prototype.execute = function (sql) {
|
|
85
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
86
|
+
var results;
|
|
87
|
+
return tslib_1.__generator(this, function (_a) {
|
|
88
|
+
switch (_a.label) {
|
|
89
|
+
case 0: return [4 /*yield*/, this.d1.execute(sql, this.params)];
|
|
90
|
+
case 1:
|
|
91
|
+
results = _a.sent();
|
|
92
|
+
return [2 /*return*/, new D1SqlResult(results)];
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
/** @deprecated use `param` instead*/
|
|
98
|
+
D1Command.prototype.addParameterAndReturnSqlToken = function (val) {
|
|
99
|
+
return this.param(val);
|
|
100
|
+
};
|
|
101
|
+
D1Command.prototype.param = function (val) {
|
|
102
|
+
var p;
|
|
103
|
+
if (val instanceof Date)
|
|
104
|
+
p = val.valueOf();
|
|
105
|
+
else if (typeof val === 'boolean')
|
|
106
|
+
p = val ? 1 : 0;
|
|
107
|
+
else
|
|
108
|
+
p = val;
|
|
109
|
+
this.params.push(p);
|
|
110
|
+
// According to https://developers.cloudflare.com/d1/worker-api/prepared-statements/
|
|
111
|
+
// only the ordered "?NNN" and anonymous "?" param types are supported (although :AAAA seems to work too)
|
|
112
|
+
var key = "?".concat(this.params.length);
|
|
113
|
+
return key;
|
|
114
|
+
};
|
|
115
|
+
return D1Command;
|
|
116
|
+
}());
|
|
117
|
+
var D1SqlResult = /** @class */ (function () {
|
|
118
|
+
function D1SqlResult(rows) {
|
|
119
|
+
if (rows === void 0) { rows = []; }
|
|
120
|
+
this.rows = rows;
|
|
121
|
+
// NOTE: are we guaranteed that when this is reached, rows is not empty?
|
|
122
|
+
this.columns = rows.length === 0 ? [] : Object.keys(rows[0]);
|
|
123
|
+
}
|
|
124
|
+
D1SqlResult.prototype.getColumnKeyInResultForIndexInSelect = function (index) {
|
|
125
|
+
return this.columns[index];
|
|
126
|
+
};
|
|
127
|
+
return D1SqlResult;
|
|
128
|
+
}());
|
package/remult-express.js
CHANGED
|
@@ -19,7 +19,10 @@ function remultApi(options) {
|
|
|
19
19
|
app.use(express.urlencoded({ extended: true, limit: options.bodySizeLimit }));
|
|
20
20
|
}
|
|
21
21
|
var server = (0, index_js_1.createRemultServer)(options, {
|
|
22
|
-
buildGenericRequestInfo: function (req) { return
|
|
22
|
+
buildGenericRequestInfo: function (req) { return ({
|
|
23
|
+
internal: tslib_1.__assign(tslib_1.__assign({}, req), { on: req.on }),
|
|
24
|
+
public: { headers: new Headers(req.headers) },
|
|
25
|
+
}); },
|
|
23
26
|
getRequestBody: function (req) { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
|
|
24
27
|
return [2 /*return*/, req.body];
|
|
25
28
|
}); }); },
|
package/remult-fastify.js
CHANGED
|
@@ -39,7 +39,12 @@ function remultApi(options) {
|
|
|
39
39
|
return response;
|
|
40
40
|
}
|
|
41
41
|
var api = (0, index_js_1.createRemultServer)(options, {
|
|
42
|
-
buildGenericRequestInfo: function (req) { return
|
|
42
|
+
buildGenericRequestInfo: function (req) { return ({
|
|
43
|
+
internal: tslib_1.__assign(tslib_1.__assign({}, req), { url: req.originalUrl,
|
|
44
|
+
// @ts-ignore
|
|
45
|
+
on: req.on }),
|
|
46
|
+
public: { headers: new Headers(req.headers) },
|
|
47
|
+
}); },
|
|
43
48
|
getRequestBody: function (req) { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
|
|
44
49
|
return [2 /*return*/, req.body];
|
|
45
50
|
}); }); },
|
package/remult-fresh.js
CHANGED
|
@@ -7,7 +7,11 @@ var remult_api_server_js_1 = require("./server/remult-api-server.js");
|
|
|
7
7
|
function remultApi(options, response) {
|
|
8
8
|
var _this = this;
|
|
9
9
|
var server = (0, remult_api_server_js_1.createRemultServerCore)(options, {
|
|
10
|
-
buildGenericRequestInfo: function (r) { return
|
|
10
|
+
buildGenericRequestInfo: function (r) { return ({
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
internal: tslib_1.__assign(tslib_1.__assign({}, r), { on: r.on }),
|
|
13
|
+
public: { headers: r.headers },
|
|
14
|
+
}); },
|
|
11
15
|
getRequestBody: function (req) { return req.json(); },
|
|
12
16
|
});
|
|
13
17
|
return {
|
package/remult-hapi.js
CHANGED
|
@@ -9,13 +9,10 @@ function remultApi(options) {
|
|
|
9
9
|
var _this = this;
|
|
10
10
|
var api = (0, index_js_1.createRemultServer)(options, {
|
|
11
11
|
buildGenericRequestInfo: function (req) { return ({
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
on: function (e, do1) {
|
|
17
|
-
req.raw.req.on('close', do1);
|
|
18
|
-
},
|
|
12
|
+
internal: tslib_1.__assign(tslib_1.__assign({}, req), { url: req.url.pathname, on: function (e, do1) {
|
|
13
|
+
req.raw.req.on('close', do1);
|
|
14
|
+
} }),
|
|
15
|
+
public: { headers: new Headers(req.headers) },
|
|
19
16
|
}); },
|
|
20
17
|
getRequestBody: function (req) { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
|
|
21
18
|
return [2 /*return*/, req.payload];
|
package/remult-hono.js
CHANGED
|
@@ -12,22 +12,24 @@ function remultApi(options) {
|
|
|
12
12
|
var api = (0, index_js_1.createRemultServer)(options, {
|
|
13
13
|
buildGenericRequestInfo: function (c) {
|
|
14
14
|
return {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
internal: {
|
|
16
|
+
method: c.req.method,
|
|
17
|
+
params: c.req.param(),
|
|
18
|
+
query: new Proxy(c.req, {
|
|
19
|
+
get: function (target, prop) {
|
|
20
|
+
var r = c.req.queries(prop);
|
|
21
|
+
if ((r === null || r === void 0 ? void 0 : r.length) == 1)
|
|
22
|
+
return r[0];
|
|
23
|
+
return r;
|
|
24
|
+
},
|
|
25
|
+
}),
|
|
26
|
+
url: c.req.url,
|
|
27
|
+
on: function (e, do1) {
|
|
28
|
+
;
|
|
29
|
+
c['_tempOnClose'](function () { return do1(); });
|
|
23
30
|
},
|
|
24
|
-
}),
|
|
25
|
-
url: c.req.url,
|
|
26
|
-
on: function (e, do1) {
|
|
27
|
-
;
|
|
28
|
-
c['_tempOnClose'](function () { return do1(); });
|
|
29
|
-
// c.req.on('close', do1)
|
|
30
31
|
},
|
|
32
|
+
public: { headers: new Headers(c.req.header()) },
|
|
31
33
|
};
|
|
32
34
|
},
|
|
33
35
|
getRequestBody: function (c) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
package/remult-next.js
CHANGED
|
@@ -8,7 +8,10 @@ var index_js_1 = require("./server/index.js");
|
|
|
8
8
|
function remultNext(options) {
|
|
9
9
|
var _this = this;
|
|
10
10
|
var result = (0, index_js_1.createRemultServer)(options, {
|
|
11
|
-
buildGenericRequestInfo: function (req) { return
|
|
11
|
+
buildGenericRequestInfo: function (req) { return ({
|
|
12
|
+
internal: tslib_1.__assign(tslib_1.__assign({}, req), { on: req.on }),
|
|
13
|
+
public: { headers: new Headers(req.headers) },
|
|
14
|
+
}); },
|
|
12
15
|
getRequestBody: function (req) { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
|
|
13
16
|
return [2 /*return*/, req.body];
|
|
14
17
|
}); }); },
|
|
@@ -84,14 +87,17 @@ function remultApi(options) {
|
|
|
84
87
|
var result = (0, index_js_1.createRemultServer)(options, {
|
|
85
88
|
getRequestBody: function (req) { return req.json(); },
|
|
86
89
|
buildGenericRequestInfo: function (req) { return ({
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
90
|
+
internal: {
|
|
91
|
+
url: req === null || req === void 0 ? void 0 : req.url,
|
|
92
|
+
method: req === null || req === void 0 ? void 0 : req.method,
|
|
93
|
+
on: function (e, do1) {
|
|
94
|
+
if (e === 'close') {
|
|
95
|
+
;
|
|
96
|
+
req['_tempOnClose'] = do1;
|
|
97
|
+
}
|
|
98
|
+
},
|
|
94
99
|
},
|
|
100
|
+
public: { headers: req.headers },
|
|
95
101
|
}); },
|
|
96
102
|
});
|
|
97
103
|
var handler = function (req) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
package/remult-nuxt.js
CHANGED
|
@@ -8,8 +8,8 @@ var index_js_1 = require("./server/index.js");
|
|
|
8
8
|
function remultApi(options) {
|
|
9
9
|
var _this = this;
|
|
10
10
|
var result = (0, index_js_1.createRemultServer)(options, {
|
|
11
|
-
buildGenericRequestInfo: function (event) {
|
|
12
|
-
|
|
11
|
+
buildGenericRequestInfo: function (event) { return ({
|
|
12
|
+
internal: {
|
|
13
13
|
method: event.node.req.method,
|
|
14
14
|
url: event.node.req.url,
|
|
15
15
|
on: function (a, b) {
|
|
@@ -17,8 +17,11 @@ function remultApi(options) {
|
|
|
17
17
|
b();
|
|
18
18
|
});
|
|
19
19
|
},
|
|
20
|
-
}
|
|
21
|
-
|
|
20
|
+
},
|
|
21
|
+
public: {
|
|
22
|
+
headers: new Headers(event.node.req.headers),
|
|
23
|
+
},
|
|
24
|
+
}); },
|
|
22
25
|
getRequestBody: function (event) { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
|
|
23
26
|
switch (_a.label) {
|
|
24
27
|
case 0: return [4 /*yield*/, (0, h3_1.readBody)(event)];
|
package/remult-solid-start.js
CHANGED
|
@@ -9,13 +9,16 @@ function remultApi(options) {
|
|
|
9
9
|
var _this = this;
|
|
10
10
|
var result = (0, index_js_1.createRemultServer)(options, {
|
|
11
11
|
buildGenericRequestInfo: function (event) { return ({
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
internal: {
|
|
13
|
+
url: event.request.url,
|
|
14
|
+
method: event.request.method,
|
|
15
|
+
on: function (e, do1) {
|
|
16
|
+
if (e === 'close') {
|
|
17
|
+
event.locals['_tempOnClose'] = do1;
|
|
18
|
+
}
|
|
19
|
+
},
|
|
18
20
|
},
|
|
21
|
+
public: { headers: new Headers(event.request.headers) },
|
|
19
22
|
}); },
|
|
20
23
|
getRequestBody: function (event) { return event.request.json(); },
|
|
21
24
|
});
|