@payloadcms/db-d1-sqlite 0.0.1-beta.0 → 3.58.0-internal.df9fce5
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 +29 -2
- package/dist/connect.d.ts +3 -0
- package/dist/connect.d.ts.map +1 -0
- package/dist/connect.js +54 -0
- package/dist/connect.js.map +1 -0
- package/dist/drizzle-proxy/d1.d.ts +2 -0
- package/dist/drizzle-proxy/d1.d.ts.map +1 -0
- package/dist/drizzle-proxy/d1.js +3 -0
- package/dist/drizzle-proxy/d1.js.map +1 -0
- package/dist/drizzle-proxy/index.d.ts +2 -0
- package/dist/drizzle-proxy/index.d.ts.map +1 -0
- package/dist/drizzle-proxy/index.js +3 -0
- package/dist/drizzle-proxy/index.js.map +1 -0
- package/dist/drizzle-proxy/miniflare-d1.d.ts +2 -0
- package/dist/drizzle-proxy/miniflare-d1.d.ts.map +1 -0
- package/dist/drizzle-proxy/miniflare-d1.js +3 -0
- package/dist/drizzle-proxy/miniflare-d1.js.map +1 -0
- package/dist/drizzle-proxy/relations.d.ts +2 -0
- package/dist/drizzle-proxy/relations.d.ts.map +1 -0
- package/dist/drizzle-proxy/relations.js +3 -0
- package/dist/drizzle-proxy/relations.js.map +1 -0
- package/dist/drizzle-proxy/sqlite-core.d.ts +2 -0
- package/dist/drizzle-proxy/sqlite-core.d.ts.map +1 -0
- package/dist/drizzle-proxy/sqlite-core.js +3 -0
- package/dist/drizzle-proxy/sqlite-core.js.map +1 -0
- package/dist/execute.d.ts +3 -0
- package/dist/execute.d.ts.map +1 -0
- package/dist/execute.js +28 -0
- package/dist/execute.js.map +1 -0
- package/dist/exports/types-deprecated.d.ts +62 -0
- package/dist/exports/types-deprecated.d.ts.map +1 -0
- package/dist/exports/types-deprecated.js +5 -0
- package/dist/exports/types-deprecated.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +140 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +164 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +4 -0
- package/dist/types.js.map +1 -0
- package/package.json +94 -1
- package/.prettierignore +0 -12
- package/.swcrc +0 -24
- package/eslint.config.js +0 -18
- package/src/addresses/addressesCollection.ts +0 -76
- package/src/addresses/defaultAddressFields.ts +0 -83
- package/src/addresses/defaultCountries.ts +0 -50
- package/src/carts/beforeChange.ts +0 -51
- package/src/carts/cartsCollection.ts +0 -146
- package/src/currencies/index.ts +0 -29
- package/src/endpoints/confirmOrder.ts +0 -312
- package/src/endpoints/initiatePayment.ts +0 -322
- package/src/exports/addresses.ts +0 -2
- package/src/exports/currencies.ts +0 -1
- package/src/exports/fields.ts +0 -5
- package/src/exports/orders.ts +0 -1
- package/src/exports/payments/stripe.ts +0 -1
- package/src/exports/plugin.ts +0 -1
- package/src/exports/products.ts +0 -1
- package/src/exports/react.ts +0 -8
- package/src/exports/transactions.ts +0 -1
- package/src/exports/translations.ts +0 -1
- package/src/exports/types.ts +0 -7
- package/src/exports/ui.ts +0 -3
- package/src/exports/variants.ts +0 -5
- package/src/fields/amountField.ts +0 -43
- package/src/fields/cartItemsField.ts +0 -84
- package/src/fields/currencyField.ts +0 -39
- package/src/fields/inventoryField.ts +0 -22
- package/src/fields/pricesField.ts +0 -65
- package/src/fields/statusField.ts +0 -57
- package/src/fields/variantsFields.ts +0 -56
- package/src/index.ts +0 -275
- package/src/orders/ordersCollection.ts +0 -157
- package/src/payments/adapters/stripe/confirmOrder.ts +0 -123
- package/src/payments/adapters/stripe/endpoints/webhooks.ts +0 -69
- package/src/payments/adapters/stripe/index.ts +0 -135
- package/src/payments/adapters/stripe/initiatePayment.ts +0 -131
- package/src/products/productsCollection.ts +0 -78
- package/src/react/provider/index.tsx +0 -893
- package/src/react/provider/types.ts +0 -184
- package/src/react/provider/utilities.ts +0 -22
- package/src/transactions/transactionsCollection.ts +0 -166
- package/src/translations/en.ts +0 -64
- package/src/translations/index.ts +0 -11
- package/src/translations/translation-schema.json +0 -35
- package/src/types.ts +0 -403
- package/src/ui/PriceInput/FormattedInput.tsx +0 -134
- package/src/ui/PriceInput/index.scss +0 -28
- package/src/ui/PriceInput/index.tsx +0 -43
- package/src/ui/PriceInput/utilities.ts +0 -46
- package/src/ui/PriceRowLabel/index.css +0 -13
- package/src/ui/PriceRowLabel/index.tsx +0 -56
- package/src/ui/VariantOptionsSelector/ErrorBox.tsx +0 -27
- package/src/ui/VariantOptionsSelector/OptionsSelect.tsx +0 -78
- package/src/ui/VariantOptionsSelector/index.css +0 -37
- package/src/ui/VariantOptionsSelector/index.tsx +0 -83
- package/src/utilities/defaultProductsValidation.ts +0 -42
- package/src/utilities/errorCodes.ts +0 -14
- package/src/utilities/getCollectionSlugMap.ts +0 -84
- package/src/utilities/sanitizePluginConfig.ts +0 -80
- package/src/variants/variantOptionsCollection.ts +0 -59
- package/src/variants/variantTypesCollection.ts +0 -55
- package/src/variants/variantsCollection/hooks/beforeChange.ts +0 -47
- package/src/variants/variantsCollection/hooks/validateOptions.ts +0 -72
- package/src/variants/variantsCollection/index.ts +0 -119
- package/tsconfig.json +0 -7
- package/tsconfig.tsbuildinfo +0 -1
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import type { ResultSet } from '@libsql/client';
|
|
2
|
+
import type { D1Database, DatabaseBinding } from '@miniflare/d1';
|
|
3
|
+
import type { extendDrizzleTable } from '@payloadcms/drizzle';
|
|
4
|
+
import type { BaseSQLiteAdapter, BaseSQLiteArgs } from '@payloadcms/drizzle/sqlite';
|
|
5
|
+
import type { BuildQueryJoinAliases, DrizzleAdapter } from '@payloadcms/drizzle/types';
|
|
6
|
+
import type { DrizzleConfig, Relation, Relations, SQL } from 'drizzle-orm';
|
|
7
|
+
import type { DrizzleD1Database } from 'drizzle-orm/d1';
|
|
8
|
+
import type { LibSQLDatabase } from 'drizzle-orm/libsql';
|
|
9
|
+
import type { AnySQLiteColumn, SQLiteInsertOnConflictDoUpdateConfig, SQLiteTableWithColumns, SQLiteTransactionConfig } from 'drizzle-orm/sqlite-core';
|
|
10
|
+
import type { SQLiteRaw } from 'drizzle-orm/sqlite-core/query-builders/raw';
|
|
11
|
+
import type { Payload, PayloadRequest } from 'payload';
|
|
12
|
+
type SQLiteSchema = {
|
|
13
|
+
relations: Record<string, GenericRelation>;
|
|
14
|
+
tables: Record<string, SQLiteTableWithColumns<any>>;
|
|
15
|
+
};
|
|
16
|
+
type SQLiteSchemaHookArgs = {
|
|
17
|
+
extendTable: typeof extendDrizzleTable;
|
|
18
|
+
schema: SQLiteSchema;
|
|
19
|
+
};
|
|
20
|
+
export type SQLiteSchemaHook = (args: SQLiteSchemaHookArgs) => Promise<SQLiteSchema> | SQLiteSchema;
|
|
21
|
+
export type Args = {
|
|
22
|
+
binding: DatabaseBinding;
|
|
23
|
+
} & BaseSQLiteArgs;
|
|
24
|
+
export type GenericColumns = {
|
|
25
|
+
[x: string]: AnySQLiteColumn;
|
|
26
|
+
};
|
|
27
|
+
export type GenericTable = SQLiteTableWithColumns<{
|
|
28
|
+
columns: GenericColumns;
|
|
29
|
+
dialect: string;
|
|
30
|
+
name: string;
|
|
31
|
+
schema: string;
|
|
32
|
+
}>;
|
|
33
|
+
export type GenericRelation = Relations<string, Record<string, Relation<string>>>;
|
|
34
|
+
export type CountDistinct = (args: {
|
|
35
|
+
db: LibSQLDatabase;
|
|
36
|
+
joins: BuildQueryJoinAliases;
|
|
37
|
+
tableName: string;
|
|
38
|
+
where: SQL;
|
|
39
|
+
}) => Promise<number>;
|
|
40
|
+
export type DeleteWhere = (args: {
|
|
41
|
+
db: LibSQLDatabase;
|
|
42
|
+
tableName: string;
|
|
43
|
+
where: SQL;
|
|
44
|
+
}) => Promise<void>;
|
|
45
|
+
export type DropDatabase = (args: {
|
|
46
|
+
adapter: SQLiteD1Adapter;
|
|
47
|
+
}) => Promise<void>;
|
|
48
|
+
export type Execute<T> = (args: {
|
|
49
|
+
db?: LibSQLDatabase;
|
|
50
|
+
drizzle?: LibSQLDatabase;
|
|
51
|
+
raw?: string;
|
|
52
|
+
sql?: SQL<unknown>;
|
|
53
|
+
}) => SQLiteRaw<Promise<T>> | SQLiteRaw<ResultSet>;
|
|
54
|
+
export type Insert = (args: {
|
|
55
|
+
db: LibSQLDatabase;
|
|
56
|
+
onConflictDoUpdate?: SQLiteInsertOnConflictDoUpdateConfig<any>;
|
|
57
|
+
tableName: string;
|
|
58
|
+
values: Record<string, unknown> | Record<string, unknown>[];
|
|
59
|
+
}) => Promise<Record<string, unknown>[]>;
|
|
60
|
+
type SQLiteDrizzleAdapter = Omit<DrizzleAdapter, 'countDistinct' | 'deleteWhere' | 'drizzle' | 'dropDatabase' | 'execute' | 'idType' | 'insert' | 'operators' | 'relations'>;
|
|
61
|
+
export interface GeneratedDatabaseSchema {
|
|
62
|
+
schemaUntyped: Record<string, unknown>;
|
|
63
|
+
}
|
|
64
|
+
type Drizzle = {
|
|
65
|
+
$client: D1Database;
|
|
66
|
+
} & DrizzleD1Database<Record<string, any>>;
|
|
67
|
+
export type SQLiteD1Adapter = {
|
|
68
|
+
binding: Args['binding'];
|
|
69
|
+
client: D1Database;
|
|
70
|
+
drizzle: Drizzle;
|
|
71
|
+
} & BaseSQLiteAdapter & SQLiteDrizzleAdapter;
|
|
72
|
+
export type IDType = 'integer' | 'numeric' | 'text';
|
|
73
|
+
export type MigrateUpArgs = {
|
|
74
|
+
/**
|
|
75
|
+
* The SQLite Drizzle instance that you can use to execute SQL directly within the current transaction.
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* import { type MigrateUpArgs, sql } from '@payloadcms/db-sqlite'
|
|
79
|
+
*
|
|
80
|
+
* export async function up({ db, payload, req }: MigrateUpArgs): Promise<void> {
|
|
81
|
+
* const { rows: posts } = await db.run(sql`SELECT * FROM posts`)
|
|
82
|
+
* }
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
db: Drizzle;
|
|
86
|
+
/**
|
|
87
|
+
* The Payload instance that you can use to execute Local API methods
|
|
88
|
+
* To use the current transaction you must pass `req` to arguments
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* import { type MigrateUpArgs } from '@payloadcms/db-sqlite'
|
|
92
|
+
*
|
|
93
|
+
* export async function up({ db, payload, req }: MigrateUpArgs): Promise<void> {
|
|
94
|
+
* const posts = await payload.find({ collection: 'posts', req })
|
|
95
|
+
* }
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
payload: Payload;
|
|
99
|
+
/**
|
|
100
|
+
* The `PayloadRequest` object that contains the current transaction
|
|
101
|
+
*/
|
|
102
|
+
req: PayloadRequest;
|
|
103
|
+
};
|
|
104
|
+
export type MigrateDownArgs = {
|
|
105
|
+
/**
|
|
106
|
+
* The SQLite Drizzle instance that you can use to execute SQL directly within the current transaction.
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* import { type MigrateDownArgs, sql } from '@payloadcms/db-sqlite'
|
|
110
|
+
*
|
|
111
|
+
* export async function down({ db, payload, req }: MigrateDownArgs): Promise<void> {
|
|
112
|
+
* const { rows: posts } = await db.run(sql`SELECT * FROM posts`)
|
|
113
|
+
* }
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
db: Drizzle;
|
|
117
|
+
/**
|
|
118
|
+
* The Payload instance that you can use to execute Local API methods
|
|
119
|
+
* To use the current transaction you must pass `req` to arguments
|
|
120
|
+
* @example
|
|
121
|
+
* ```ts
|
|
122
|
+
* import { type MigrateDownArgs } from '@payloadcms/db-sqlite'
|
|
123
|
+
*
|
|
124
|
+
* export async function down({ db, payload, req }: MigrateDownArgs): Promise<void> {
|
|
125
|
+
* const posts = await payload.find({ collection: 'posts', req })
|
|
126
|
+
* }
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
payload: Payload;
|
|
130
|
+
/**
|
|
131
|
+
* The `PayloadRequest` object that contains the current transaction
|
|
132
|
+
*/
|
|
133
|
+
req: PayloadRequest;
|
|
134
|
+
};
|
|
135
|
+
declare module 'payload' {
|
|
136
|
+
interface DatabaseAdapter extends Omit<Args, 'idType' | 'logger' | 'migrationDir' | 'pool'>, DrizzleAdapter {
|
|
137
|
+
beginTransaction: (options?: SQLiteTransactionConfig) => Promise<null | number | string>;
|
|
138
|
+
drizzle: Drizzle;
|
|
139
|
+
/**
|
|
140
|
+
* An object keyed on each table, with a key value pair where the constraint name is the key, followed by the dot-notation field name
|
|
141
|
+
* Used for returning properly formed errors from unique fields
|
|
142
|
+
*/
|
|
143
|
+
fieldConstraints: Record<string, Record<string, string>>;
|
|
144
|
+
idType: Args['idType'];
|
|
145
|
+
initializing: Promise<void>;
|
|
146
|
+
localesSuffix?: string;
|
|
147
|
+
logger: DrizzleConfig['logger'];
|
|
148
|
+
prodMigrations?: {
|
|
149
|
+
down: (args: MigrateDownArgs) => Promise<void>;
|
|
150
|
+
name: string;
|
|
151
|
+
up: (args: MigrateUpArgs) => Promise<void>;
|
|
152
|
+
}[];
|
|
153
|
+
push: boolean;
|
|
154
|
+
rejectInitializing: () => void;
|
|
155
|
+
relationshipsSuffix?: string;
|
|
156
|
+
resolveInitializing: () => void;
|
|
157
|
+
schema: Record<string, GenericRelation | GenericTable>;
|
|
158
|
+
tableNameMap: Map<string, string>;
|
|
159
|
+
transactionOptions: SQLiteTransactionConfig;
|
|
160
|
+
versionsSuffix?: string;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
export {};
|
|
164
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAU,SAAS,EAAE,MAAM,gBAAgB,CAAA;AACvD,OAAO,KAAK,EAAE,UAAU,EAAa,eAAe,EAAE,MAAM,eAAe,CAAA;AAE3E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qB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libsql/client'\nimport type { D1Database, D1Options, DatabaseBinding } from '@miniflare/d1'\nconst o: D1Options = {}\nimport type { extendDrizzleTable } from '@payloadcms/drizzle'\nimport type { BaseSQLiteAdapter, BaseSQLiteArgs } from '@payloadcms/drizzle/sqlite'\nimport type { BuildQueryJoinAliases, DrizzleAdapter } from '@payloadcms/drizzle/types'\nimport type { DrizzleConfig, Relation, Relations, SQL } from 'drizzle-orm'\nimport type { DrizzleD1Database } from 'drizzle-orm/d1'\nimport type { LibSQLDatabase } from 'drizzle-orm/libsql'\nimport type {\n AnySQLiteColumn,\n SQLiteInsertOnConflictDoUpdateConfig,\n SQLiteTableWithColumns,\n SQLiteTransactionConfig,\n} from 'drizzle-orm/sqlite-core'\nimport type { SQLiteRaw } from 'drizzle-orm/sqlite-core/query-builders/raw'\nimport type { Payload, PayloadRequest } from 'payload'\n\ntype SQLiteSchema = {\n relations: Record<string, GenericRelation>\n tables: Record<string, SQLiteTableWithColumns<any>>\n}\n\ntype SQLiteSchemaHookArgs = {\n extendTable: typeof extendDrizzleTable\n schema: SQLiteSchema\n}\n\nexport type SQLiteSchemaHook = (args: SQLiteSchemaHookArgs) => Promise<SQLiteSchema> | SQLiteSchema\n\nexport type Args = {\n binding: DatabaseBinding\n} & BaseSQLiteArgs\n\nexport type GenericColumns = {\n [x: string]: AnySQLiteColumn\n}\n\nexport type GenericTable = SQLiteTableWithColumns<{\n columns: GenericColumns\n dialect: string\n name: string\n schema: string\n}>\n\nexport type GenericRelation = Relations<string, Record<string, Relation<string>>>\n\nexport type CountDistinct = (args: {\n db: LibSQLDatabase\n joins: BuildQueryJoinAliases\n tableName: string\n where: SQL\n}) => Promise<number>\n\nexport type DeleteWhere = (args: {\n db: LibSQLDatabase\n tableName: string\n where: SQL\n}) => Promise<void>\n\nexport type DropDatabase = (args: { adapter: SQLiteD1Adapter }) => Promise<void>\n\nexport type Execute<T> = (args: {\n db?: LibSQLDatabase\n drizzle?: LibSQLDatabase\n raw?: string\n sql?: SQL<unknown>\n}) => SQLiteRaw<Promise<T>> | SQLiteRaw<ResultSet>\n\nexport type Insert = (args: {\n db: LibSQLDatabase\n onConflictDoUpdate?: SQLiteInsertOnConflictDoUpdateConfig<any>\n tableName: string\n values: Record<string, unknown> | Record<string, unknown>[]\n}) => Promise<Record<string, unknown>[]>\n\n// Explicitly omit drizzle property for complete override in SQLiteAdapter, required in ts 5.5\ntype SQLiteDrizzleAdapter = Omit<\n DrizzleAdapter,\n | 'countDistinct'\n | 'deleteWhere'\n | 'drizzle'\n | 'dropDatabase'\n | 'execute'\n | 'idType'\n | 'insert'\n | 'operators'\n | 'relations'\n>\n\nexport interface GeneratedDatabaseSchema {\n schemaUntyped: Record<string, unknown>\n}\n\ntype ResolveSchemaType<T> = 'schema' extends keyof T\n ? T['schema']\n : GeneratedDatabaseSchema['schemaUntyped']\n\ntype Drizzle = { $client: D1Database } & DrizzleD1Database<Record<string, any>>\n\nexport type SQLiteD1Adapter = {\n binding: Args['binding']\n client: D1Database\n drizzle: Drizzle\n} & BaseSQLiteAdapter &\n SQLiteDrizzleAdapter\n\nexport type IDType = 'integer' | 'numeric' | 'text'\n\nexport type MigrateUpArgs = {\n /**\n * The SQLite Drizzle instance that you can use to execute SQL directly within the current transaction.\n * @example\n * ```ts\n * import { type MigrateUpArgs, sql } from '@payloadcms/db-sqlite'\n *\n * export async function up({ db, payload, req }: MigrateUpArgs): Promise<void> {\n * const { rows: posts } = await db.run(sql`SELECT * FROM posts`)\n * }\n * ```\n */\n db: Drizzle\n /**\n * The Payload instance that you can use to execute Local API methods\n * To use the current transaction you must pass `req` to arguments\n * @example\n * ```ts\n * import { type MigrateUpArgs } from '@payloadcms/db-sqlite'\n *\n * export async function up({ db, payload, req }: MigrateUpArgs): Promise<void> {\n * const posts = await payload.find({ collection: 'posts', req })\n * }\n * ```\n */\n payload: Payload\n /**\n * The `PayloadRequest` object that contains the current transaction\n */\n req: PayloadRequest\n}\nexport type MigrateDownArgs = {\n /**\n * The SQLite Drizzle instance that you can use to execute SQL directly within the current transaction.\n * @example\n * ```ts\n * import { type MigrateDownArgs, sql } from '@payloadcms/db-sqlite'\n *\n * export async function down({ db, payload, req }: MigrateDownArgs): Promise<void> {\n * const { rows: posts } = await db.run(sql`SELECT * FROM posts`)\n * }\n * ```\n */\n db: Drizzle\n /**\n * The Payload instance that you can use to execute Local API methods\n * To use the current transaction you must pass `req` to arguments\n * @example\n * ```ts\n * import { type MigrateDownArgs } from '@payloadcms/db-sqlite'\n *\n * export async function down({ db, payload, req }: MigrateDownArgs): Promise<void> {\n * const posts = await payload.find({ collection: 'posts', req })\n * }\n * ```\n */\n payload: Payload\n /**\n * The `PayloadRequest` object that contains the current transaction\n */\n req: PayloadRequest\n}\n\ndeclare module 'payload' {\n export interface DatabaseAdapter\n extends Omit<Args, 'idType' | 'logger' | 'migrationDir' | 'pool'>,\n DrizzleAdapter {\n beginTransaction: (options?: SQLiteTransactionConfig) => Promise<null | number | string>\n drizzle: Drizzle\n /**\n * An object keyed on each table, with a key value pair where the constraint name is the key, followed by the dot-notation field name\n * Used for returning properly formed errors from unique fields\n */\n fieldConstraints: Record<string, Record<string, string>>\n idType: Args['idType']\n initializing: Promise<void>\n localesSuffix?: string\n logger: DrizzleConfig['logger']\n prodMigrations?: {\n down: (args: MigrateDownArgs) => Promise<void>\n name: string\n up: (args: MigrateUpArgs) => Promise<void>\n }[]\n push: boolean\n rejectInitializing: () => void\n relationshipsSuffix?: string\n resolveInitializing: () => void\n schema: Record<string, GenericRelation | GenericTable>\n tableNameMap: Map<string, string>\n transactionOptions: SQLiteTransactionConfig\n versionsSuffix?: string\n }\n}\n"],"names":["o"],"mappings":"AAEA,MAAMA,IAAe,CAAC;AA0ItB,WA8BC"}
|
package/package.json
CHANGED
|
@@ -1,4 +1,97 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/db-d1-sqlite",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.58.0-internal.df9fce5",
|
|
4
|
+
"description": "The officially supported D1 SQLite database adapter for Payload",
|
|
5
|
+
"homepage": "https://payloadcms.com",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/payloadcms/payload.git",
|
|
9
|
+
"directory": "packages/db-d1-sqlite"
|
|
10
|
+
},
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"author": "Payload <dev@payloadcms.com> (https://payloadcms.com)",
|
|
13
|
+
"maintainers": [
|
|
14
|
+
{
|
|
15
|
+
"name": "Payload",
|
|
16
|
+
"email": "info@payloadcms.com",
|
|
17
|
+
"url": "https://payloadcms.com"
|
|
18
|
+
}
|
|
19
|
+
],
|
|
20
|
+
"type": "module",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"import": "./dist/index.js",
|
|
24
|
+
"require": "./dist/index.js",
|
|
25
|
+
"types": "./dist/index.d.ts"
|
|
26
|
+
},
|
|
27
|
+
"./types": {
|
|
28
|
+
"import": "./dist/exports/types-deprecated.js",
|
|
29
|
+
"require": "./dist/exports/types-deprecated.js",
|
|
30
|
+
"types": "./dist/exports/types-deprecated.d.ts"
|
|
31
|
+
},
|
|
32
|
+
"./migration-utils": {
|
|
33
|
+
"import": "./dist/exports/migration-utils.js",
|
|
34
|
+
"require": "./dist/exports/migration-utils.js",
|
|
35
|
+
"types": "./dist/exports/migration-utils.d.ts"
|
|
36
|
+
},
|
|
37
|
+
"./drizzle": {
|
|
38
|
+
"import": "./dist/drizzle-proxy/index.js",
|
|
39
|
+
"types": "./dist/drizzle-proxy/index.d.ts",
|
|
40
|
+
"default": "./dist/drizzle-proxy/index.js"
|
|
41
|
+
},
|
|
42
|
+
"./drizzle/sqlite-core": {
|
|
43
|
+
"import": "./dist/drizzle-proxy/sqlite-core.js",
|
|
44
|
+
"types": "./dist/drizzle-proxy/sqlite-core.d.ts",
|
|
45
|
+
"default": "./dist/drizzle-proxy/sqlite-core.js"
|
|
46
|
+
},
|
|
47
|
+
"./drizzle/d1": {
|
|
48
|
+
"import": "./dist/drizzle-proxy/d1.js",
|
|
49
|
+
"types": "./dist/drizzle-proxy/d1.d.ts",
|
|
50
|
+
"default": "./dist/drizzle-proxy/d1.js"
|
|
51
|
+
},
|
|
52
|
+
"./drizzle/relations": {
|
|
53
|
+
"import": "./dist/drizzle-proxy/relations.js",
|
|
54
|
+
"types": "./dist/drizzle-proxy/relations.d.ts",
|
|
55
|
+
"default": "./dist/drizzle-proxy/relations.js"
|
|
56
|
+
},
|
|
57
|
+
"./drizzle/miniflare": {
|
|
58
|
+
"import": "./dist/drizzle-proxy/miniflare.js",
|
|
59
|
+
"types": "./dist/drizzle-proxy/miniflare.d.ts",
|
|
60
|
+
"default": "./dist/drizzle-proxy/miniflare.js"
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"main": "./dist/index.js",
|
|
64
|
+
"types": "./dist/index.d.ts",
|
|
65
|
+
"files": [
|
|
66
|
+
"dist",
|
|
67
|
+
"mock.js"
|
|
68
|
+
],
|
|
69
|
+
"dependencies": {
|
|
70
|
+
"@miniflare/d1": "2.14.4",
|
|
71
|
+
"console-table-printer": "2.12.1",
|
|
72
|
+
"drizzle-kit": "0.28.0",
|
|
73
|
+
"drizzle-orm": "0.36.1",
|
|
74
|
+
"prompts": "2.4.2",
|
|
75
|
+
"to-snake-case": "1.0.0",
|
|
76
|
+
"uuid": "9.0.0",
|
|
77
|
+
"@payloadcms/drizzle": "3.58.0-internal.df9fce5"
|
|
78
|
+
},
|
|
79
|
+
"devDependencies": {
|
|
80
|
+
"@types/pg": "8.10.2",
|
|
81
|
+
"@types/to-snake-case": "1.0.0",
|
|
82
|
+
"@types/uuid": "10.0.0",
|
|
83
|
+
"payload": "3.58.0-internal.df9fce5",
|
|
84
|
+
"@payloadcms/eslint-config": "3.28.0"
|
|
85
|
+
},
|
|
86
|
+
"peerDependencies": {
|
|
87
|
+
"payload": "3.58.0-internal.df9fce5"
|
|
88
|
+
},
|
|
89
|
+
"scripts": {
|
|
90
|
+
"build": "pnpm build:swc && pnpm build:types",
|
|
91
|
+
"build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths",
|
|
92
|
+
"build:types": "tsc --emitDeclarationOnly --outDir dist",
|
|
93
|
+
"clean": "rimraf -g {dist,*.tsbuildinfo}",
|
|
94
|
+
"lint": "eslint .",
|
|
95
|
+
"lint:fix": "eslint . --fix"
|
|
96
|
+
}
|
|
4
97
|
}
|
package/.prettierignore
DELETED
package/.swcrc
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://json.schemastore.org/swcrc",
|
|
3
|
-
"sourceMaps": true,
|
|
4
|
-
"jsc": {
|
|
5
|
-
"target": "esnext",
|
|
6
|
-
"parser": {
|
|
7
|
-
"syntax": "typescript",
|
|
8
|
-
"tsx": true,
|
|
9
|
-
"dts": true
|
|
10
|
-
},
|
|
11
|
-
"transform": {
|
|
12
|
-
"react": {
|
|
13
|
-
"runtime": "automatic",
|
|
14
|
-
"pragmaFrag": "React.Fragment",
|
|
15
|
-
"throwIfNamespace": true,
|
|
16
|
-
"development": false,
|
|
17
|
-
"useBuiltins": true
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
"module": {
|
|
22
|
-
"type": "es6"
|
|
23
|
-
}
|
|
24
|
-
}
|
package/eslint.config.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { rootEslintConfig, rootParserOptions } from '../../eslint.config.js'
|
|
2
|
-
|
|
3
|
-
/** @typedef {import('eslint').Linter.Config} Config */
|
|
4
|
-
|
|
5
|
-
/** @type {Config[]} */
|
|
6
|
-
export const index = [
|
|
7
|
-
...rootEslintConfig,
|
|
8
|
-
{
|
|
9
|
-
languageOptions: {
|
|
10
|
-
parserOptions: {
|
|
11
|
-
...rootParserOptions,
|
|
12
|
-
tsconfigRootDir: import.meta.dirname,
|
|
13
|
-
},
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
]
|
|
17
|
-
|
|
18
|
-
export default index
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import type { CollectionConfig, Field } from 'payload'
|
|
2
|
-
|
|
3
|
-
import type { CountryType, FieldsOverride } from '../types.js'
|
|
4
|
-
|
|
5
|
-
import { defaultCountries } from './defaultCountries.js'
|
|
6
|
-
|
|
7
|
-
type Props = {
|
|
8
|
-
/**
|
|
9
|
-
* Array of fields used for capturing the address data. Use this over overrides to customise the fields here as it's reused across the plugin.
|
|
10
|
-
*/
|
|
11
|
-
addressFields: Field[]
|
|
12
|
-
/**
|
|
13
|
-
* Slug of the customers collection, defaults to 'users'.
|
|
14
|
-
*/
|
|
15
|
-
customersSlug?: string
|
|
16
|
-
overrides?: { fields?: FieldsOverride } & Partial<Omit<CollectionConfig, 'fields'>>
|
|
17
|
-
supportedCountries?: CountryType[]
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const addressesCollection: (props: Props) => CollectionConfig = (props) => {
|
|
21
|
-
const { addressFields, customersSlug = 'users', overrides } = props || {}
|
|
22
|
-
const fieldsOverride = overrides?.fields
|
|
23
|
-
|
|
24
|
-
const { supportedCountries: supportedCountriesFromProps } = props || {}
|
|
25
|
-
const supportedCountries = supportedCountriesFromProps || defaultCountries
|
|
26
|
-
const hasOnlyOneCountry = supportedCountries && supportedCountries.length === 1
|
|
27
|
-
|
|
28
|
-
const defaultFields: Field[] = [
|
|
29
|
-
{
|
|
30
|
-
name: 'customer',
|
|
31
|
-
type: 'relationship',
|
|
32
|
-
label: ({ t }) =>
|
|
33
|
-
// @ts-expect-error - translations are not typed in plugins yet
|
|
34
|
-
t('plugin-ecommerce:customer'),
|
|
35
|
-
relationTo: customersSlug,
|
|
36
|
-
},
|
|
37
|
-
...addressFields.map((field) => {
|
|
38
|
-
if ('name' in field && field.name === 'country') {
|
|
39
|
-
return {
|
|
40
|
-
name: 'country',
|
|
41
|
-
type: 'select',
|
|
42
|
-
label: ({ t }) =>
|
|
43
|
-
// @ts-expect-error - translations are not typed in plugins yet
|
|
44
|
-
t('plugin-ecommerce:addressCountry'),
|
|
45
|
-
options: supportedCountries || defaultCountries,
|
|
46
|
-
required: true,
|
|
47
|
-
...(supportedCountries && supportedCountries?.[0] && hasOnlyOneCountry
|
|
48
|
-
? {
|
|
49
|
-
defaultValue: supportedCountries?.[0].value,
|
|
50
|
-
}
|
|
51
|
-
: {}),
|
|
52
|
-
} as Field
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return field
|
|
56
|
-
}),
|
|
57
|
-
]
|
|
58
|
-
|
|
59
|
-
const fields =
|
|
60
|
-
fieldsOverride && typeof fieldsOverride === 'function'
|
|
61
|
-
? fieldsOverride({ defaultFields })
|
|
62
|
-
: defaultFields
|
|
63
|
-
|
|
64
|
-
const baseConfig: CollectionConfig = {
|
|
65
|
-
slug: 'addresses',
|
|
66
|
-
timestamps: true,
|
|
67
|
-
...overrides,
|
|
68
|
-
admin: {
|
|
69
|
-
useAsTitle: 'createdAt',
|
|
70
|
-
...overrides?.admin,
|
|
71
|
-
},
|
|
72
|
-
fields,
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return { ...baseConfig }
|
|
76
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import type { Field } from 'payload'
|
|
2
|
-
|
|
3
|
-
export const defaultAddressFields: () => Field[] = () => {
|
|
4
|
-
return [
|
|
5
|
-
{
|
|
6
|
-
name: 'title',
|
|
7
|
-
type: 'text',
|
|
8
|
-
label: ({ t }) =>
|
|
9
|
-
// @ts-expect-error - translations are not typed in plugins yet
|
|
10
|
-
t('plugin-ecommerce:addressTitle'),
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
name: 'firstName',
|
|
14
|
-
type: 'text',
|
|
15
|
-
label: ({ t }) =>
|
|
16
|
-
// @ts-expect-error - translations are not typed in plugins yet
|
|
17
|
-
t('plugin-ecommerce:addressFirstName'),
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
name: 'lastName',
|
|
21
|
-
type: 'text',
|
|
22
|
-
label: ({ t }) =>
|
|
23
|
-
// @ts-expect-error - translations are not typed in plugins yet
|
|
24
|
-
t('plugin-ecommerce:addressLastName'),
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
name: 'company',
|
|
28
|
-
type: 'text',
|
|
29
|
-
label: ({ t }) =>
|
|
30
|
-
// @ts-expect-error - translations are not typed in plugins yet
|
|
31
|
-
t('plugin-ecommerce:addressCompany'),
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
name: 'addressLine1',
|
|
35
|
-
type: 'text',
|
|
36
|
-
label: ({ t }) =>
|
|
37
|
-
// @ts-expect-error - translations are not typed in plugins yet
|
|
38
|
-
t('plugin-ecommerce:addressLine1'),
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
name: 'addressLine2',
|
|
42
|
-
type: 'text',
|
|
43
|
-
label: ({ t }) =>
|
|
44
|
-
// @ts-expect-error - translations are not typed in plugins yet
|
|
45
|
-
t('plugin-ecommerce:addressLine2'),
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
name: 'city',
|
|
49
|
-
type: 'text',
|
|
50
|
-
label: ({ t }) =>
|
|
51
|
-
// @ts-expect-error - translations are not typed in plugins yet
|
|
52
|
-
t('plugin-ecommerce:addressCity'),
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
name: 'state',
|
|
56
|
-
type: 'text',
|
|
57
|
-
label: ({ t }) =>
|
|
58
|
-
// @ts-expect-error - translations are not typed in plugins yet
|
|
59
|
-
t('plugin-ecommerce:addressState'),
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
name: 'postalCode',
|
|
63
|
-
type: 'text',
|
|
64
|
-
label: ({ t }) =>
|
|
65
|
-
// @ts-expect-error - translations are not typed in plugins yet
|
|
66
|
-
t('plugin-ecommerce:addressPostalCode'),
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
name: 'country',
|
|
70
|
-
type: 'text',
|
|
71
|
-
label: ({ t }) =>
|
|
72
|
-
// @ts-expect-error - translations are not typed in plugins yet
|
|
73
|
-
t('plugin-ecommerce:addressCountry'),
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
name: 'phone',
|
|
77
|
-
type: 'text',
|
|
78
|
-
label: ({ t }) =>
|
|
79
|
-
// @ts-expect-error - translations are not typed in plugins yet
|
|
80
|
-
t('plugin-ecommerce:addressPhone'),
|
|
81
|
-
},
|
|
82
|
-
]
|
|
83
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import type { CountryType } from '../types.js'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Default list of countries supported for forms and payments.
|
|
5
|
-
* This can be overriden or reused in other parts of the application.
|
|
6
|
-
*
|
|
7
|
-
* The label is the human-readable name of the country, and the value is the ISO 3166-1 alpha-2 code.
|
|
8
|
-
*/
|
|
9
|
-
export const defaultCountries: CountryType[] = [
|
|
10
|
-
{ label: 'United States', value: 'US' },
|
|
11
|
-
{ label: 'United Kingdom', value: 'GB' },
|
|
12
|
-
{ label: 'Canada', value: 'CA' },
|
|
13
|
-
{ label: 'Australia', value: 'AU' },
|
|
14
|
-
{ label: 'Austria', value: 'AT' },
|
|
15
|
-
{ label: 'Belgium', value: 'BE' },
|
|
16
|
-
{ label: 'Brazil', value: 'BR' },
|
|
17
|
-
{ label: 'Bulgaria', value: 'BG' },
|
|
18
|
-
{ label: 'Cyprus', value: 'CY' },
|
|
19
|
-
{ label: 'Czech Republic', value: 'CZ' },
|
|
20
|
-
{ label: 'Denmark', value: 'DK' },
|
|
21
|
-
{ label: 'Estonia', value: 'EE' },
|
|
22
|
-
{ label: 'Finland', value: 'FI' },
|
|
23
|
-
{ label: 'France', value: 'FR' },
|
|
24
|
-
{ label: 'Germany', value: 'DE' },
|
|
25
|
-
{ label: 'Greece', value: 'GR' },
|
|
26
|
-
{ label: 'Hong Kong', value: 'HK' },
|
|
27
|
-
{ label: 'Hungary', value: 'HU' },
|
|
28
|
-
{ label: 'India', value: 'IN' },
|
|
29
|
-
{ label: 'Ireland', value: 'IE' },
|
|
30
|
-
{ label: 'Italy', value: 'IT' },
|
|
31
|
-
{ label: 'Japan', value: 'JP' },
|
|
32
|
-
{ label: 'Latvia', value: 'LV' },
|
|
33
|
-
{ label: 'Lithuania', value: 'LT' },
|
|
34
|
-
{ label: 'Luxembourg', value: 'LU' },
|
|
35
|
-
{ label: 'Malaysia', value: 'MY' },
|
|
36
|
-
{ label: 'Malta', value: 'MT' },
|
|
37
|
-
{ label: 'Mexico', value: 'MX' },
|
|
38
|
-
{ label: 'Netherlands', value: 'NL' },
|
|
39
|
-
{ label: 'New Zealand', value: 'NZ' },
|
|
40
|
-
{ label: 'Norway', value: 'NO' },
|
|
41
|
-
{ label: 'Poland', value: 'PL' },
|
|
42
|
-
{ label: 'Portugal', value: 'PT' },
|
|
43
|
-
{ label: 'Romania', value: 'RO' },
|
|
44
|
-
{ label: 'Singapore', value: 'SG' },
|
|
45
|
-
{ label: 'Slovakia', value: 'SK' },
|
|
46
|
-
{ label: 'Slovenia', value: 'SI' },
|
|
47
|
-
{ label: 'Spain', value: 'ES' },
|
|
48
|
-
{ label: 'Sweden', value: 'SE' },
|
|
49
|
-
{ label: 'Switzerland', value: 'CH' },
|
|
50
|
-
]
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import type { CollectionBeforeChangeHook } from 'payload'
|
|
2
|
-
|
|
3
|
-
type Props = {
|
|
4
|
-
productsSlug: string
|
|
5
|
-
variantsSlug: string
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const beforeChangeCart: (args: Props) => CollectionBeforeChangeHook =
|
|
9
|
-
({ productsSlug, variantsSlug }) =>
|
|
10
|
-
async ({ data, req }) => {
|
|
11
|
-
// Update subtotal based on items in the cart
|
|
12
|
-
if (data.items && Array.isArray(data.items)) {
|
|
13
|
-
const priceField = `priceIn${data.currency}`
|
|
14
|
-
|
|
15
|
-
let subtotal = 0
|
|
16
|
-
|
|
17
|
-
for (const item of data.items) {
|
|
18
|
-
if (item.variant) {
|
|
19
|
-
const id = typeof item.variant === 'object' ? item.variant.id : item.variant
|
|
20
|
-
|
|
21
|
-
const variant = await req.payload.findByID({
|
|
22
|
-
id,
|
|
23
|
-
collection: variantsSlug,
|
|
24
|
-
depth: 0,
|
|
25
|
-
select: {
|
|
26
|
-
[priceField]: true,
|
|
27
|
-
},
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
subtotal += variant[priceField] * item.quantity
|
|
31
|
-
} else {
|
|
32
|
-
const id = typeof item.product === 'object' ? item.product.id : item.product
|
|
33
|
-
|
|
34
|
-
const product = await req.payload.findByID({
|
|
35
|
-
id,
|
|
36
|
-
collection: productsSlug,
|
|
37
|
-
depth: 0,
|
|
38
|
-
select: {
|
|
39
|
-
[priceField]: true,
|
|
40
|
-
},
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
subtotal += product[priceField] * item.quantity
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
data.subtotal = subtotal
|
|
48
|
-
} else {
|
|
49
|
-
data.subtotal = 0
|
|
50
|
-
}
|
|
51
|
-
}
|