@onyx.dev/onyx-database 0.2.10 → 1.0.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/README.md +168 -3
- package/dist/gen/cli/generate.cjs +1367 -112
- package/dist/gen/cli/generate.cjs.map +1 -1
- package/dist/index.cjs +207 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +144 -3
- package/dist/index.d.ts +144 -3
- package/dist/index.js +206 -17
- package/dist/index.js.map +1 -1
- package/dist/schema/cli/schema.cjs +1991 -0
- package/dist/schema/cli/schema.cjs.map +1 -0
- package/package.json +4 -2
package/dist/index.d.cts
CHANGED
|
@@ -1014,6 +1014,66 @@ interface IOnyxDatabase<Schema = Record<string, unknown>> {
|
|
|
1014
1014
|
* @param documentId ID of the document to delete.
|
|
1015
1015
|
*/
|
|
1016
1016
|
deleteDocument(documentId: string): Promise<unknown>;
|
|
1017
|
+
/**
|
|
1018
|
+
* Fetch the current schema for the configured database.
|
|
1019
|
+
*
|
|
1020
|
+
* @example
|
|
1021
|
+
* ```ts
|
|
1022
|
+
* const schema = await db.getSchema();
|
|
1023
|
+
* const userOnly = await db.getSchema({ tables: ['User'] });
|
|
1024
|
+
* ```
|
|
1025
|
+
*/
|
|
1026
|
+
getSchema(options?: {
|
|
1027
|
+
tables?: string | string[];
|
|
1028
|
+
}): Promise<SchemaRevision>;
|
|
1029
|
+
/**
|
|
1030
|
+
* Retrieve the schema revision history for the configured database.
|
|
1031
|
+
*/
|
|
1032
|
+
getSchemaHistory(): Promise<SchemaHistoryEntry[]>;
|
|
1033
|
+
/**
|
|
1034
|
+
* Update the schema for the configured database.
|
|
1035
|
+
*
|
|
1036
|
+
* @example
|
|
1037
|
+
* ```ts
|
|
1038
|
+
* await db.updateSchema({
|
|
1039
|
+
* revisionDescription: 'Add profile table',
|
|
1040
|
+
* entities: [
|
|
1041
|
+
* {
|
|
1042
|
+
* name: 'Profile',
|
|
1043
|
+
* identifier: { name: 'id', generator: 'UUID' },
|
|
1044
|
+
* attributes: [
|
|
1045
|
+
* { name: 'displayName', type: 'String', isNullable: false }
|
|
1046
|
+
* ]
|
|
1047
|
+
* }
|
|
1048
|
+
* ]
|
|
1049
|
+
* }, { publish: true });
|
|
1050
|
+
* ```
|
|
1051
|
+
*/
|
|
1052
|
+
updateSchema(schema: SchemaUpsertRequest, options?: {
|
|
1053
|
+
publish?: boolean;
|
|
1054
|
+
}): Promise<SchemaRevision>;
|
|
1055
|
+
/**
|
|
1056
|
+
* Validate a schema definition without applying it to the database.
|
|
1057
|
+
*/
|
|
1058
|
+
validateSchema(schema: SchemaUpsertRequest): Promise<SchemaValidationResult>;
|
|
1059
|
+
/**
|
|
1060
|
+
* List stored secrets for the configured database.
|
|
1061
|
+
*/
|
|
1062
|
+
listSecrets(): Promise<SecretsListResponse>;
|
|
1063
|
+
/**
|
|
1064
|
+
* Fetch a decrypted secret value by key.
|
|
1065
|
+
*/
|
|
1066
|
+
getSecret(key: string): Promise<SecretRecord>;
|
|
1067
|
+
/**
|
|
1068
|
+
* Create or update a secret.
|
|
1069
|
+
*/
|
|
1070
|
+
putSecret(key: string, input: SecretSaveRequest): Promise<SecretMetadata>;
|
|
1071
|
+
/**
|
|
1072
|
+
* Delete a secret by key.
|
|
1073
|
+
*/
|
|
1074
|
+
deleteSecret(key: string): Promise<{
|
|
1075
|
+
key: string;
|
|
1076
|
+
}>;
|
|
1017
1077
|
/**
|
|
1018
1078
|
* Cancels active streams; safe to call multiple times.
|
|
1019
1079
|
* @example
|
|
@@ -1053,6 +1113,83 @@ interface OnyxFacade {
|
|
|
1053
1113
|
*/
|
|
1054
1114
|
clearCacheConfig(): void;
|
|
1055
1115
|
}
|
|
1116
|
+
interface SecretMetadata {
|
|
1117
|
+
key: string;
|
|
1118
|
+
purpose?: string;
|
|
1119
|
+
updatedAt: Date;
|
|
1120
|
+
}
|
|
1121
|
+
interface SecretRecord extends SecretMetadata {
|
|
1122
|
+
value: string;
|
|
1123
|
+
}
|
|
1124
|
+
interface SecretsListResponse {
|
|
1125
|
+
records: SecretMetadata[];
|
|
1126
|
+
meta: {
|
|
1127
|
+
totalRecords: number;
|
|
1128
|
+
};
|
|
1129
|
+
}
|
|
1130
|
+
interface SecretSaveRequest {
|
|
1131
|
+
purpose?: string;
|
|
1132
|
+
value?: string;
|
|
1133
|
+
}
|
|
1134
|
+
type SchemaDataType = 'String' | 'Boolean' | 'Char' | 'Byte' | 'Short' | 'Int' | 'Float' | 'Double' | 'Long' | 'Timestamp' | 'EmbeddedObject' | 'EmbeddedList';
|
|
1135
|
+
type SchemaIdentifierGenerator = 'None' | 'Sequence' | 'UUID';
|
|
1136
|
+
interface SchemaIdentifier {
|
|
1137
|
+
name: string;
|
|
1138
|
+
generator?: SchemaIdentifierGenerator;
|
|
1139
|
+
type?: SchemaDataType | string;
|
|
1140
|
+
}
|
|
1141
|
+
interface SchemaAttribute {
|
|
1142
|
+
name: string;
|
|
1143
|
+
type: SchemaDataType | string;
|
|
1144
|
+
isNullable?: boolean;
|
|
1145
|
+
}
|
|
1146
|
+
type SchemaIndexType = 'DEFAULT' | 'LUCENE' | string;
|
|
1147
|
+
interface SchemaIndex {
|
|
1148
|
+
name: string;
|
|
1149
|
+
type?: SchemaIndexType;
|
|
1150
|
+
minimumScore?: number;
|
|
1151
|
+
}
|
|
1152
|
+
interface SchemaResolver {
|
|
1153
|
+
name: string;
|
|
1154
|
+
resolver: string;
|
|
1155
|
+
}
|
|
1156
|
+
type SchemaTriggerEvent = 'PreInsert' | 'PostInsert' | 'PrePersist' | 'PostPersist' | 'PreUpdate' | 'PostUpdate' | 'PreDelete' | 'PostDelete' | string;
|
|
1157
|
+
interface SchemaTrigger {
|
|
1158
|
+
name: string;
|
|
1159
|
+
event: SchemaTriggerEvent;
|
|
1160
|
+
trigger: string;
|
|
1161
|
+
}
|
|
1162
|
+
interface SchemaEntity {
|
|
1163
|
+
name: string;
|
|
1164
|
+
identifier?: SchemaIdentifier;
|
|
1165
|
+
partition?: string;
|
|
1166
|
+
attributes?: SchemaAttribute[];
|
|
1167
|
+
indexes?: SchemaIndex[];
|
|
1168
|
+
resolvers?: SchemaResolver[];
|
|
1169
|
+
triggers?: SchemaTrigger[];
|
|
1170
|
+
}
|
|
1171
|
+
interface SchemaRevisionMetadata {
|
|
1172
|
+
revisionId?: string;
|
|
1173
|
+
createdAt?: Date;
|
|
1174
|
+
publishedAt?: Date;
|
|
1175
|
+
}
|
|
1176
|
+
interface SchemaRevision {
|
|
1177
|
+
databaseId: string;
|
|
1178
|
+
revisionDescription?: string;
|
|
1179
|
+
entities: SchemaEntity[];
|
|
1180
|
+
meta?: SchemaRevisionMetadata;
|
|
1181
|
+
}
|
|
1182
|
+
type SchemaHistoryEntry = SchemaRevision;
|
|
1183
|
+
type SchemaUpsertRequest = Omit<SchemaRevision, 'databaseId' | 'meta'> & {
|
|
1184
|
+
databaseId?: string;
|
|
1185
|
+
};
|
|
1186
|
+
interface SchemaValidationResult {
|
|
1187
|
+
valid?: boolean;
|
|
1188
|
+
schema?: SchemaRevision;
|
|
1189
|
+
errors?: Array<{
|
|
1190
|
+
message: string;
|
|
1191
|
+
}>;
|
|
1192
|
+
}
|
|
1056
1193
|
|
|
1057
1194
|
/** -------------------------
|
|
1058
1195
|
* Facade export
|
|
@@ -1150,8 +1287,12 @@ declare class ConditionBuilderImpl implements IConditionBuilder {
|
|
|
1150
1287
|
|
|
1151
1288
|
declare const eq: (field: string, value: unknown) => ConditionBuilderImpl;
|
|
1152
1289
|
declare const neq: (field: string, value: unknown) => ConditionBuilderImpl;
|
|
1153
|
-
declare
|
|
1154
|
-
declare
|
|
1290
|
+
declare function inOp(field: string, values: string): ConditionBuilderImpl;
|
|
1291
|
+
declare function inOp<T>(field: string, values: unknown[] | IQueryBuilder<T>): ConditionBuilderImpl;
|
|
1292
|
+
declare function within<T>(field: string, values: string | unknown[] | IQueryBuilder<T>): ConditionBuilderImpl;
|
|
1293
|
+
declare function notIn(field: string, values: string): ConditionBuilderImpl;
|
|
1294
|
+
declare function notIn<T>(field: string, values: unknown[] | IQueryBuilder<T>): ConditionBuilderImpl;
|
|
1295
|
+
declare function notWithin<T>(field: string, values: string | unknown[] | IQueryBuilder<T>): ConditionBuilderImpl;
|
|
1155
1296
|
declare const between: (field: string, lower: unknown, upper: unknown) => ConditionBuilderImpl;
|
|
1156
1297
|
declare const gt: (field: string, value: unknown) => ConditionBuilderImpl;
|
|
1157
1298
|
declare const gte: (field: string, value: unknown) => ConditionBuilderImpl;
|
|
@@ -1187,4 +1328,4 @@ declare const percentile: (attribute: string, p: number) => string;
|
|
|
1187
1328
|
declare const sdkName = "@onyx.dev/onyx-database";
|
|
1188
1329
|
declare const sdkVersion = "0.1.0";
|
|
1189
1330
|
|
|
1190
|
-
export { type FetchImpl, type FetchResponse, type ICascadeBuilder, type ICascadeRelationshipBuilder, type IConditionBuilder, type IOnyxDatabase, type IQueryBuilder, type ISaveBuilder, type LogicalOperator, type OnyxConfig, type OnyxDocument, type OnyxFacade, type QueryCondition, type QueryCriteria, type QueryCriteriaOperator, type QueryPage, QueryResults, type QueryResultsPromise, type SelectQuery, type Sort, type StreamAction, type UpdateQuery, asc, avg, between, contains, containsIgnoreCase, count, desc, eq, gt, gte, inOp, isNull, like, lower, lt, lte, matches, max, median, min, neq, notContains, notContainsIgnoreCase, notIn, notLike, notMatches, notNull, notStartsWith, onyx, percentile, replace, sdkName, sdkVersion, startsWith, std, substring, sum, upper, variance };
|
|
1331
|
+
export { type FetchImpl, type FetchResponse, type ICascadeBuilder, type ICascadeRelationshipBuilder, type IConditionBuilder, type IOnyxDatabase, type IQueryBuilder, type ISaveBuilder, type LogicalOperator, type OnyxConfig, type OnyxDocument, type OnyxFacade, type QueryCondition, type QueryCriteria, type QueryCriteriaOperator, type QueryPage, QueryResults, type QueryResultsPromise, type SchemaAttribute, type SchemaDataType, type SchemaEntity, type SchemaHistoryEntry, type SchemaIdentifier, type SchemaIdentifierGenerator, type SchemaIndex, type SchemaIndexType, type SchemaResolver, type SchemaRevision, type SchemaRevisionMetadata, type SchemaTrigger, type SchemaTriggerEvent, type SchemaUpsertRequest, type SchemaValidationResult, type SecretMetadata, type SecretRecord, type SecretSaveRequest, type SecretsListResponse, type SelectQuery, type Sort, type StreamAction, type UpdateQuery, asc, avg, between, contains, containsIgnoreCase, count, desc, eq, gt, gte, inOp, isNull, like, lower, lt, lte, matches, max, median, min, neq, notContains, notContainsIgnoreCase, notIn, notLike, notMatches, notNull, notStartsWith, notWithin, onyx, percentile, replace, sdkName, sdkVersion, startsWith, std, substring, sum, upper, variance, within };
|
package/dist/index.d.ts
CHANGED
|
@@ -1014,6 +1014,66 @@ interface IOnyxDatabase<Schema = Record<string, unknown>> {
|
|
|
1014
1014
|
* @param documentId ID of the document to delete.
|
|
1015
1015
|
*/
|
|
1016
1016
|
deleteDocument(documentId: string): Promise<unknown>;
|
|
1017
|
+
/**
|
|
1018
|
+
* Fetch the current schema for the configured database.
|
|
1019
|
+
*
|
|
1020
|
+
* @example
|
|
1021
|
+
* ```ts
|
|
1022
|
+
* const schema = await db.getSchema();
|
|
1023
|
+
* const userOnly = await db.getSchema({ tables: ['User'] });
|
|
1024
|
+
* ```
|
|
1025
|
+
*/
|
|
1026
|
+
getSchema(options?: {
|
|
1027
|
+
tables?: string | string[];
|
|
1028
|
+
}): Promise<SchemaRevision>;
|
|
1029
|
+
/**
|
|
1030
|
+
* Retrieve the schema revision history for the configured database.
|
|
1031
|
+
*/
|
|
1032
|
+
getSchemaHistory(): Promise<SchemaHistoryEntry[]>;
|
|
1033
|
+
/**
|
|
1034
|
+
* Update the schema for the configured database.
|
|
1035
|
+
*
|
|
1036
|
+
* @example
|
|
1037
|
+
* ```ts
|
|
1038
|
+
* await db.updateSchema({
|
|
1039
|
+
* revisionDescription: 'Add profile table',
|
|
1040
|
+
* entities: [
|
|
1041
|
+
* {
|
|
1042
|
+
* name: 'Profile',
|
|
1043
|
+
* identifier: { name: 'id', generator: 'UUID' },
|
|
1044
|
+
* attributes: [
|
|
1045
|
+
* { name: 'displayName', type: 'String', isNullable: false }
|
|
1046
|
+
* ]
|
|
1047
|
+
* }
|
|
1048
|
+
* ]
|
|
1049
|
+
* }, { publish: true });
|
|
1050
|
+
* ```
|
|
1051
|
+
*/
|
|
1052
|
+
updateSchema(schema: SchemaUpsertRequest, options?: {
|
|
1053
|
+
publish?: boolean;
|
|
1054
|
+
}): Promise<SchemaRevision>;
|
|
1055
|
+
/**
|
|
1056
|
+
* Validate a schema definition without applying it to the database.
|
|
1057
|
+
*/
|
|
1058
|
+
validateSchema(schema: SchemaUpsertRequest): Promise<SchemaValidationResult>;
|
|
1059
|
+
/**
|
|
1060
|
+
* List stored secrets for the configured database.
|
|
1061
|
+
*/
|
|
1062
|
+
listSecrets(): Promise<SecretsListResponse>;
|
|
1063
|
+
/**
|
|
1064
|
+
* Fetch a decrypted secret value by key.
|
|
1065
|
+
*/
|
|
1066
|
+
getSecret(key: string): Promise<SecretRecord>;
|
|
1067
|
+
/**
|
|
1068
|
+
* Create or update a secret.
|
|
1069
|
+
*/
|
|
1070
|
+
putSecret(key: string, input: SecretSaveRequest): Promise<SecretMetadata>;
|
|
1071
|
+
/**
|
|
1072
|
+
* Delete a secret by key.
|
|
1073
|
+
*/
|
|
1074
|
+
deleteSecret(key: string): Promise<{
|
|
1075
|
+
key: string;
|
|
1076
|
+
}>;
|
|
1017
1077
|
/**
|
|
1018
1078
|
* Cancels active streams; safe to call multiple times.
|
|
1019
1079
|
* @example
|
|
@@ -1053,6 +1113,83 @@ interface OnyxFacade {
|
|
|
1053
1113
|
*/
|
|
1054
1114
|
clearCacheConfig(): void;
|
|
1055
1115
|
}
|
|
1116
|
+
interface SecretMetadata {
|
|
1117
|
+
key: string;
|
|
1118
|
+
purpose?: string;
|
|
1119
|
+
updatedAt: Date;
|
|
1120
|
+
}
|
|
1121
|
+
interface SecretRecord extends SecretMetadata {
|
|
1122
|
+
value: string;
|
|
1123
|
+
}
|
|
1124
|
+
interface SecretsListResponse {
|
|
1125
|
+
records: SecretMetadata[];
|
|
1126
|
+
meta: {
|
|
1127
|
+
totalRecords: number;
|
|
1128
|
+
};
|
|
1129
|
+
}
|
|
1130
|
+
interface SecretSaveRequest {
|
|
1131
|
+
purpose?: string;
|
|
1132
|
+
value?: string;
|
|
1133
|
+
}
|
|
1134
|
+
type SchemaDataType = 'String' | 'Boolean' | 'Char' | 'Byte' | 'Short' | 'Int' | 'Float' | 'Double' | 'Long' | 'Timestamp' | 'EmbeddedObject' | 'EmbeddedList';
|
|
1135
|
+
type SchemaIdentifierGenerator = 'None' | 'Sequence' | 'UUID';
|
|
1136
|
+
interface SchemaIdentifier {
|
|
1137
|
+
name: string;
|
|
1138
|
+
generator?: SchemaIdentifierGenerator;
|
|
1139
|
+
type?: SchemaDataType | string;
|
|
1140
|
+
}
|
|
1141
|
+
interface SchemaAttribute {
|
|
1142
|
+
name: string;
|
|
1143
|
+
type: SchemaDataType | string;
|
|
1144
|
+
isNullable?: boolean;
|
|
1145
|
+
}
|
|
1146
|
+
type SchemaIndexType = 'DEFAULT' | 'LUCENE' | string;
|
|
1147
|
+
interface SchemaIndex {
|
|
1148
|
+
name: string;
|
|
1149
|
+
type?: SchemaIndexType;
|
|
1150
|
+
minimumScore?: number;
|
|
1151
|
+
}
|
|
1152
|
+
interface SchemaResolver {
|
|
1153
|
+
name: string;
|
|
1154
|
+
resolver: string;
|
|
1155
|
+
}
|
|
1156
|
+
type SchemaTriggerEvent = 'PreInsert' | 'PostInsert' | 'PrePersist' | 'PostPersist' | 'PreUpdate' | 'PostUpdate' | 'PreDelete' | 'PostDelete' | string;
|
|
1157
|
+
interface SchemaTrigger {
|
|
1158
|
+
name: string;
|
|
1159
|
+
event: SchemaTriggerEvent;
|
|
1160
|
+
trigger: string;
|
|
1161
|
+
}
|
|
1162
|
+
interface SchemaEntity {
|
|
1163
|
+
name: string;
|
|
1164
|
+
identifier?: SchemaIdentifier;
|
|
1165
|
+
partition?: string;
|
|
1166
|
+
attributes?: SchemaAttribute[];
|
|
1167
|
+
indexes?: SchemaIndex[];
|
|
1168
|
+
resolvers?: SchemaResolver[];
|
|
1169
|
+
triggers?: SchemaTrigger[];
|
|
1170
|
+
}
|
|
1171
|
+
interface SchemaRevisionMetadata {
|
|
1172
|
+
revisionId?: string;
|
|
1173
|
+
createdAt?: Date;
|
|
1174
|
+
publishedAt?: Date;
|
|
1175
|
+
}
|
|
1176
|
+
interface SchemaRevision {
|
|
1177
|
+
databaseId: string;
|
|
1178
|
+
revisionDescription?: string;
|
|
1179
|
+
entities: SchemaEntity[];
|
|
1180
|
+
meta?: SchemaRevisionMetadata;
|
|
1181
|
+
}
|
|
1182
|
+
type SchemaHistoryEntry = SchemaRevision;
|
|
1183
|
+
type SchemaUpsertRequest = Omit<SchemaRevision, 'databaseId' | 'meta'> & {
|
|
1184
|
+
databaseId?: string;
|
|
1185
|
+
};
|
|
1186
|
+
interface SchemaValidationResult {
|
|
1187
|
+
valid?: boolean;
|
|
1188
|
+
schema?: SchemaRevision;
|
|
1189
|
+
errors?: Array<{
|
|
1190
|
+
message: string;
|
|
1191
|
+
}>;
|
|
1192
|
+
}
|
|
1056
1193
|
|
|
1057
1194
|
/** -------------------------
|
|
1058
1195
|
* Facade export
|
|
@@ -1150,8 +1287,12 @@ declare class ConditionBuilderImpl implements IConditionBuilder {
|
|
|
1150
1287
|
|
|
1151
1288
|
declare const eq: (field: string, value: unknown) => ConditionBuilderImpl;
|
|
1152
1289
|
declare const neq: (field: string, value: unknown) => ConditionBuilderImpl;
|
|
1153
|
-
declare
|
|
1154
|
-
declare
|
|
1290
|
+
declare function inOp(field: string, values: string): ConditionBuilderImpl;
|
|
1291
|
+
declare function inOp<T>(field: string, values: unknown[] | IQueryBuilder<T>): ConditionBuilderImpl;
|
|
1292
|
+
declare function within<T>(field: string, values: string | unknown[] | IQueryBuilder<T>): ConditionBuilderImpl;
|
|
1293
|
+
declare function notIn(field: string, values: string): ConditionBuilderImpl;
|
|
1294
|
+
declare function notIn<T>(field: string, values: unknown[] | IQueryBuilder<T>): ConditionBuilderImpl;
|
|
1295
|
+
declare function notWithin<T>(field: string, values: string | unknown[] | IQueryBuilder<T>): ConditionBuilderImpl;
|
|
1155
1296
|
declare const between: (field: string, lower: unknown, upper: unknown) => ConditionBuilderImpl;
|
|
1156
1297
|
declare const gt: (field: string, value: unknown) => ConditionBuilderImpl;
|
|
1157
1298
|
declare const gte: (field: string, value: unknown) => ConditionBuilderImpl;
|
|
@@ -1187,4 +1328,4 @@ declare const percentile: (attribute: string, p: number) => string;
|
|
|
1187
1328
|
declare const sdkName = "@onyx.dev/onyx-database";
|
|
1188
1329
|
declare const sdkVersion = "0.1.0";
|
|
1189
1330
|
|
|
1190
|
-
export { type FetchImpl, type FetchResponse, type ICascadeBuilder, type ICascadeRelationshipBuilder, type IConditionBuilder, type IOnyxDatabase, type IQueryBuilder, type ISaveBuilder, type LogicalOperator, type OnyxConfig, type OnyxDocument, type OnyxFacade, type QueryCondition, type QueryCriteria, type QueryCriteriaOperator, type QueryPage, QueryResults, type QueryResultsPromise, type SelectQuery, type Sort, type StreamAction, type UpdateQuery, asc, avg, between, contains, containsIgnoreCase, count, desc, eq, gt, gte, inOp, isNull, like, lower, lt, lte, matches, max, median, min, neq, notContains, notContainsIgnoreCase, notIn, notLike, notMatches, notNull, notStartsWith, onyx, percentile, replace, sdkName, sdkVersion, startsWith, std, substring, sum, upper, variance };
|
|
1331
|
+
export { type FetchImpl, type FetchResponse, type ICascadeBuilder, type ICascadeRelationshipBuilder, type IConditionBuilder, type IOnyxDatabase, type IQueryBuilder, type ISaveBuilder, type LogicalOperator, type OnyxConfig, type OnyxDocument, type OnyxFacade, type QueryCondition, type QueryCriteria, type QueryCriteriaOperator, type QueryPage, QueryResults, type QueryResultsPromise, type SchemaAttribute, type SchemaDataType, type SchemaEntity, type SchemaHistoryEntry, type SchemaIdentifier, type SchemaIdentifierGenerator, type SchemaIndex, type SchemaIndexType, type SchemaResolver, type SchemaRevision, type SchemaRevisionMetadata, type SchemaTrigger, type SchemaTriggerEvent, type SchemaUpsertRequest, type SchemaValidationResult, type SecretMetadata, type SecretRecord, type SecretSaveRequest, type SecretsListResponse, type SelectQuery, type Sort, type StreamAction, type UpdateQuery, asc, avg, between, contains, containsIgnoreCase, count, desc, eq, gt, gte, inOp, isNull, like, lower, lt, lte, matches, max, median, min, neq, notContains, notContainsIgnoreCase, notIn, notLike, notMatches, notNull, notStartsWith, notWithin, onyx, percentile, replace, sdkName, sdkVersion, startsWith, std, substring, sum, upper, variance, within };
|
package/dist/index.js
CHANGED
|
@@ -340,7 +340,8 @@ var HttpClient = class {
|
|
|
340
340
|
...method === "DELETE" ? { Prefer: "return=representation" } : {},
|
|
341
341
|
...extraHeaders ?? {}
|
|
342
342
|
});
|
|
343
|
-
|
|
343
|
+
const hasExplicitContentType = extraHeaders && "Content-Type" in extraHeaders || Object.prototype.hasOwnProperty.call(this.defaults, "Content-Type");
|
|
344
|
+
if (body == null && !hasExplicitContentType) delete headers["Content-Type"];
|
|
344
345
|
if (this.requestLoggingEnabled) {
|
|
345
346
|
console.log(`${method} ${url}`);
|
|
346
347
|
if (body != null) {
|
|
@@ -830,6 +831,56 @@ var QueryResults = class extends Array {
|
|
|
830
831
|
}
|
|
831
832
|
};
|
|
832
833
|
|
|
834
|
+
// src/helpers/condition-normalizer.ts
|
|
835
|
+
function isQueryBuilderLike(value) {
|
|
836
|
+
return !!value && typeof value.toSerializableQueryObject === "function";
|
|
837
|
+
}
|
|
838
|
+
function normalizeCriteriaValue(value) {
|
|
839
|
+
if (Array.isArray(value)) {
|
|
840
|
+
let changed = false;
|
|
841
|
+
const normalized = value.map((item) => {
|
|
842
|
+
const result = normalizeCriteriaValue(item);
|
|
843
|
+
if (result.changed) changed = true;
|
|
844
|
+
return result.value;
|
|
845
|
+
});
|
|
846
|
+
if (!changed) {
|
|
847
|
+
for (let i = 0; i < normalized.length; i += 1) {
|
|
848
|
+
if (normalized[i] !== value[i]) {
|
|
849
|
+
changed = true;
|
|
850
|
+
break;
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
return { value: changed ? normalized : value, changed };
|
|
855
|
+
}
|
|
856
|
+
if (isQueryBuilderLike(value)) {
|
|
857
|
+
return { value: value.toSerializableQueryObject(), changed: true };
|
|
858
|
+
}
|
|
859
|
+
return { value, changed: false };
|
|
860
|
+
}
|
|
861
|
+
function normalizeConditionInternal(condition) {
|
|
862
|
+
if (condition.conditionType === "SingleCondition") {
|
|
863
|
+
const { value, changed: changed2 } = normalizeCriteriaValue(condition.criteria.value);
|
|
864
|
+
if (!changed2) return condition;
|
|
865
|
+
return {
|
|
866
|
+
...condition,
|
|
867
|
+
criteria: { ...condition.criteria, value }
|
|
868
|
+
};
|
|
869
|
+
}
|
|
870
|
+
let changed = false;
|
|
871
|
+
const normalizedConditions = condition.conditions.map((child) => {
|
|
872
|
+
const normalized = normalizeConditionInternal(child);
|
|
873
|
+
if (normalized !== child) changed = true;
|
|
874
|
+
return normalized;
|
|
875
|
+
});
|
|
876
|
+
if (!changed) return condition;
|
|
877
|
+
return { ...condition, conditions: normalizedConditions };
|
|
878
|
+
}
|
|
879
|
+
function normalizeCondition(condition) {
|
|
880
|
+
if (!condition) return condition;
|
|
881
|
+
return normalizeConditionInternal(condition);
|
|
882
|
+
}
|
|
883
|
+
|
|
833
884
|
// src/builders/cascade-relationship-builder.ts
|
|
834
885
|
var CascadeRelationshipBuilder = class {
|
|
835
886
|
graphName;
|
|
@@ -957,6 +1008,37 @@ function serializeDates(value) {
|
|
|
957
1008
|
}
|
|
958
1009
|
return value;
|
|
959
1010
|
}
|
|
1011
|
+
function stripEntityText(input) {
|
|
1012
|
+
const { entityText, ...rest } = input;
|
|
1013
|
+
return rest;
|
|
1014
|
+
}
|
|
1015
|
+
function normalizeSecretMetadata(input) {
|
|
1016
|
+
return { ...input, updatedAt: new Date(input.updatedAt) };
|
|
1017
|
+
}
|
|
1018
|
+
function normalizeSecretRecord(input) {
|
|
1019
|
+
return { ...input, updatedAt: new Date(input.updatedAt) };
|
|
1020
|
+
}
|
|
1021
|
+
function normalizeDate(value) {
|
|
1022
|
+
if (value == null) return void 0;
|
|
1023
|
+
if (value instanceof Date) return value;
|
|
1024
|
+
const ts = new Date(value);
|
|
1025
|
+
return Number.isNaN(ts.getTime()) ? void 0 : ts;
|
|
1026
|
+
}
|
|
1027
|
+
function normalizeSchemaRevision(input, fallbackDatabaseId) {
|
|
1028
|
+
const { meta, createdAt, publishedAt, revisionId, entityText, ...rest } = input;
|
|
1029
|
+
const mergedMeta = {
|
|
1030
|
+
revisionId: meta?.revisionId ?? revisionId,
|
|
1031
|
+
createdAt: normalizeDate(meta?.createdAt ?? createdAt),
|
|
1032
|
+
publishedAt: normalizeDate(meta?.publishedAt ?? publishedAt)
|
|
1033
|
+
};
|
|
1034
|
+
const cleanedMeta = mergedMeta.revisionId || mergedMeta.createdAt || mergedMeta.publishedAt ? mergedMeta : void 0;
|
|
1035
|
+
return {
|
|
1036
|
+
...rest,
|
|
1037
|
+
databaseId: input.databaseId ?? fallbackDatabaseId,
|
|
1038
|
+
meta: cleanedMeta,
|
|
1039
|
+
entities: input.entities ?? []
|
|
1040
|
+
};
|
|
1041
|
+
}
|
|
960
1042
|
var OnyxDatabaseImpl = class {
|
|
961
1043
|
cfgPromise;
|
|
962
1044
|
resolved = null;
|
|
@@ -1090,6 +1172,94 @@ var OnyxDatabaseImpl = class {
|
|
|
1090
1172
|
)}`;
|
|
1091
1173
|
return http.request("DELETE", path);
|
|
1092
1174
|
}
|
|
1175
|
+
async getSchema(options) {
|
|
1176
|
+
const { http, databaseId } = await this.ensureClient();
|
|
1177
|
+
const params = new URLSearchParams();
|
|
1178
|
+
const tables = options?.tables;
|
|
1179
|
+
const tableList = Array.isArray(tables) ? tables : typeof tables === "string" ? tables.split(",") : [];
|
|
1180
|
+
const normalizedTables = tableList.map((t) => t.trim()).filter(Boolean);
|
|
1181
|
+
if (normalizedTables.length) {
|
|
1182
|
+
params.append("tables", normalizedTables.map(encodeURIComponent).join(","));
|
|
1183
|
+
}
|
|
1184
|
+
const path = `/schemas/${encodeURIComponent(databaseId)}${params.size ? `?${params.toString()}` : ""}`;
|
|
1185
|
+
const res = await http.request("GET", path);
|
|
1186
|
+
return normalizeSchemaRevision(res, databaseId);
|
|
1187
|
+
}
|
|
1188
|
+
async getSchemaHistory() {
|
|
1189
|
+
const { http, databaseId } = await this.ensureClient();
|
|
1190
|
+
const path = `/schemas/history/${encodeURIComponent(databaseId)}`;
|
|
1191
|
+
const res = await http.request("GET", path);
|
|
1192
|
+
return Array.isArray(res) ? res.map((entry) => normalizeSchemaRevision(entry, databaseId)) : [];
|
|
1193
|
+
}
|
|
1194
|
+
async updateSchema(schema, options) {
|
|
1195
|
+
const { http, databaseId } = await this.ensureClient();
|
|
1196
|
+
const params = new URLSearchParams();
|
|
1197
|
+
if (options?.publish) params.append("publish", "true");
|
|
1198
|
+
const path = `/schemas/${encodeURIComponent(databaseId)}${params.size ? `?${params.toString()}` : ""}`;
|
|
1199
|
+
const body = stripEntityText({ ...schema, databaseId: schema.databaseId ?? databaseId });
|
|
1200
|
+
const res = await http.request(
|
|
1201
|
+
"PUT",
|
|
1202
|
+
path,
|
|
1203
|
+
serializeDates(body)
|
|
1204
|
+
);
|
|
1205
|
+
return normalizeSchemaRevision(res, databaseId);
|
|
1206
|
+
}
|
|
1207
|
+
async validateSchema(schema) {
|
|
1208
|
+
const { http, databaseId } = await this.ensureClient();
|
|
1209
|
+
const path = `/schemas/${encodeURIComponent(databaseId)}/validate`;
|
|
1210
|
+
const body = stripEntityText({ ...schema, databaseId: schema.databaseId ?? databaseId });
|
|
1211
|
+
const res = await http.request(
|
|
1212
|
+
"POST",
|
|
1213
|
+
path,
|
|
1214
|
+
serializeDates(body)
|
|
1215
|
+
);
|
|
1216
|
+
const normalizedSchema = res.schema ? normalizeSchemaRevision(res.schema, databaseId) : void 0;
|
|
1217
|
+
return {
|
|
1218
|
+
...res,
|
|
1219
|
+
valid: res.valid ?? true,
|
|
1220
|
+
schema: normalizedSchema
|
|
1221
|
+
};
|
|
1222
|
+
}
|
|
1223
|
+
async listSecrets() {
|
|
1224
|
+
const { http, databaseId } = await this.ensureClient();
|
|
1225
|
+
const path = `/database/${encodeURIComponent(databaseId)}/secret`;
|
|
1226
|
+
const response = await http.request(
|
|
1227
|
+
"GET",
|
|
1228
|
+
path,
|
|
1229
|
+
void 0,
|
|
1230
|
+
{ "Content-Type": "application/json" }
|
|
1231
|
+
);
|
|
1232
|
+
const records = (response.records ?? []).map(normalizeSecretMetadata);
|
|
1233
|
+
return {
|
|
1234
|
+
...response,
|
|
1235
|
+
records,
|
|
1236
|
+
meta: response.meta ?? { totalRecords: records.length }
|
|
1237
|
+
};
|
|
1238
|
+
}
|
|
1239
|
+
async getSecret(key) {
|
|
1240
|
+
const { http, databaseId } = await this.ensureClient();
|
|
1241
|
+
const path = `/database/${encodeURIComponent(databaseId)}/secret/${encodeURIComponent(key)}`;
|
|
1242
|
+
const record = await http.request("GET", path, void 0, {
|
|
1243
|
+
"Content-Type": "application/json"
|
|
1244
|
+
});
|
|
1245
|
+
return normalizeSecretRecord(record);
|
|
1246
|
+
}
|
|
1247
|
+
async putSecret(key, input) {
|
|
1248
|
+
const { http, databaseId } = await this.ensureClient();
|
|
1249
|
+
const path = `/database/${encodeURIComponent(databaseId)}/secret/${encodeURIComponent(key)}`;
|
|
1250
|
+
const response = await http.request("PUT", path, serializeDates(input));
|
|
1251
|
+
return normalizeSecretMetadata(response);
|
|
1252
|
+
}
|
|
1253
|
+
async deleteSecret(key) {
|
|
1254
|
+
const { http, databaseId } = await this.ensureClient();
|
|
1255
|
+
const path = `/database/${encodeURIComponent(databaseId)}/secret/${encodeURIComponent(key)}`;
|
|
1256
|
+
const response = await http.request(
|
|
1257
|
+
"DELETE",
|
|
1258
|
+
path
|
|
1259
|
+
);
|
|
1260
|
+
const deletedKey = response && typeof response === "object" && "key" in response ? response.key : void 0;
|
|
1261
|
+
return { key: deletedKey ?? key };
|
|
1262
|
+
}
|
|
1093
1263
|
close() {
|
|
1094
1264
|
for (const h of Array.from(this.streams)) {
|
|
1095
1265
|
try {
|
|
@@ -1204,11 +1374,14 @@ var QueryBuilderImpl = class {
|
|
|
1204
1374
|
if (!this.table) throw new Error("Table is not defined. Call from(<table>) first.");
|
|
1205
1375
|
return this.table;
|
|
1206
1376
|
}
|
|
1377
|
+
serializableConditions() {
|
|
1378
|
+
return normalizeCondition(this.conditions);
|
|
1379
|
+
}
|
|
1207
1380
|
toSelectQuery() {
|
|
1208
1381
|
return {
|
|
1209
1382
|
type: "SelectQuery",
|
|
1210
1383
|
fields: this.fields,
|
|
1211
|
-
conditions: this.
|
|
1384
|
+
conditions: this.serializableConditions(),
|
|
1212
1385
|
sort: this.sort,
|
|
1213
1386
|
limit: this.limitValue,
|
|
1214
1387
|
distinct: this.distinctValue,
|
|
@@ -1217,6 +1390,21 @@ var QueryBuilderImpl = class {
|
|
|
1217
1390
|
resolvers: this.resolvers
|
|
1218
1391
|
};
|
|
1219
1392
|
}
|
|
1393
|
+
toUpdateQuery() {
|
|
1394
|
+
return {
|
|
1395
|
+
type: "UpdateQuery",
|
|
1396
|
+
conditions: this.serializableConditions(),
|
|
1397
|
+
updates: this.updates ?? {},
|
|
1398
|
+
sort: this.sort,
|
|
1399
|
+
limit: this.limitValue,
|
|
1400
|
+
partition: this.partitionValue ?? null
|
|
1401
|
+
};
|
|
1402
|
+
}
|
|
1403
|
+
toSerializableQueryObject() {
|
|
1404
|
+
const table = this.ensureTable();
|
|
1405
|
+
const payload = this.mode === "update" ? this.toUpdateQuery() : this.toSelectQuery();
|
|
1406
|
+
return { ...payload, table };
|
|
1407
|
+
}
|
|
1220
1408
|
from(table) {
|
|
1221
1409
|
this.table = table;
|
|
1222
1410
|
return this;
|
|
@@ -1352,14 +1540,7 @@ var QueryBuilderImpl = class {
|
|
|
1352
1540
|
async update() {
|
|
1353
1541
|
if (this.mode !== "update") throw new Error("Call setUpdates(...) before update().");
|
|
1354
1542
|
const table = this.ensureTable();
|
|
1355
|
-
const update =
|
|
1356
|
-
type: "UpdateQuery",
|
|
1357
|
-
conditions: this.conditions,
|
|
1358
|
-
updates: this.updates ?? {},
|
|
1359
|
-
sort: this.sort,
|
|
1360
|
-
limit: this.limitValue,
|
|
1361
|
-
partition: this.partitionValue ?? null
|
|
1362
|
-
};
|
|
1543
|
+
const update = this.toUpdateQuery();
|
|
1363
1544
|
return this.db._update(table, update, this.partitionValue);
|
|
1364
1545
|
}
|
|
1365
1546
|
onItemAdded(listener) {
|
|
@@ -1572,12 +1753,20 @@ var ConditionBuilderImpl = class {
|
|
|
1572
1753
|
var c = (field, operator, value) => new ConditionBuilderImpl({ field, operator, value });
|
|
1573
1754
|
var eq = (field, value) => c(field, "EQUAL", value);
|
|
1574
1755
|
var neq = (field, value) => c(field, "NOT_EQUAL", value);
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
"IN",
|
|
1578
|
-
|
|
1579
|
-
)
|
|
1580
|
-
|
|
1756
|
+
function inOp(field, values) {
|
|
1757
|
+
const parsed = typeof values === "string" ? values.split(",").map((v) => v.trim()).filter((v) => v.length) : values;
|
|
1758
|
+
return c(field, "IN", parsed);
|
|
1759
|
+
}
|
|
1760
|
+
function within(field, values) {
|
|
1761
|
+
return inOp(field, values);
|
|
1762
|
+
}
|
|
1763
|
+
function notIn(field, values) {
|
|
1764
|
+
const parsed = typeof values === "string" ? values.split(",").map((v) => v.trim()).filter((v) => v.length) : values;
|
|
1765
|
+
return c(field, "NOT_IN", parsed);
|
|
1766
|
+
}
|
|
1767
|
+
function notWithin(field, values) {
|
|
1768
|
+
return notIn(field, values);
|
|
1769
|
+
}
|
|
1581
1770
|
var between = (field, lower2, upper2) => c(field, "BETWEEN", [lower2, upper2]);
|
|
1582
1771
|
var gt = (field, value) => c(field, "GREATER_THAN", value);
|
|
1583
1772
|
var gte = (field, value) => c(field, "GREATER_THAN_EQUAL", value);
|
|
@@ -1615,6 +1804,6 @@ var percentile = (attribute, p) => `percentile(${attribute}, ${p})`;
|
|
|
1615
1804
|
var sdkName = "@onyx.dev/onyx-database";
|
|
1616
1805
|
var sdkVersion = "0.1.0";
|
|
1617
1806
|
|
|
1618
|
-
export { QueryResults, asc, avg, between, contains, containsIgnoreCase, count, desc, eq, gt, gte, inOp, isNull, like, lower, lt, lte, matches, max, median, min, neq, notContains, notContainsIgnoreCase, notIn, notLike, notMatches, notNull, notStartsWith, onyx, percentile, replace, sdkName, sdkVersion, startsWith, std, substring, sum, upper, variance };
|
|
1807
|
+
export { QueryResults, asc, avg, between, contains, containsIgnoreCase, count, desc, eq, gt, gte, inOp, isNull, like, lower, lt, lte, matches, max, median, min, neq, notContains, notContainsIgnoreCase, notIn, notLike, notMatches, notNull, notStartsWith, notWithin, onyx, percentile, replace, sdkName, sdkVersion, startsWith, std, substring, sum, upper, variance, within };
|
|
1619
1808
|
//# sourceMappingURL=index.js.map
|
|
1620
1809
|
//# sourceMappingURL=index.js.map
|