@payloadcms/db-d1-sqlite 0.0.1-beta.0 → 3.58.0-canary.4

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.
Files changed (105) hide show
  1. package/README.md +32 -2
  2. package/dist/connect.d.ts +3 -0
  3. package/dist/connect.d.ts.map +1 -0
  4. package/dist/connect.js +53 -0
  5. package/dist/connect.js.map +1 -0
  6. package/dist/drizzle-proxy/d1.d.ts +2 -0
  7. package/dist/drizzle-proxy/d1.d.ts.map +1 -0
  8. package/dist/drizzle-proxy/d1.js +3 -0
  9. package/dist/drizzle-proxy/d1.js.map +1 -0
  10. package/dist/drizzle-proxy/index.d.ts +2 -0
  11. package/dist/drizzle-proxy/index.d.ts.map +1 -0
  12. package/dist/drizzle-proxy/index.js +3 -0
  13. package/dist/drizzle-proxy/index.js.map +1 -0
  14. package/dist/drizzle-proxy/relations.d.ts +2 -0
  15. package/dist/drizzle-proxy/relations.d.ts.map +1 -0
  16. package/dist/drizzle-proxy/relations.js +3 -0
  17. package/dist/drizzle-proxy/relations.js.map +1 -0
  18. package/dist/drizzle-proxy/sqlite-core.d.ts +2 -0
  19. package/dist/drizzle-proxy/sqlite-core.d.ts.map +1 -0
  20. package/dist/drizzle-proxy/sqlite-core.js +3 -0
  21. package/dist/drizzle-proxy/sqlite-core.js.map +1 -0
  22. package/dist/execute.d.ts +3 -0
  23. package/dist/execute.d.ts.map +1 -0
  24. package/dist/execute.js +28 -0
  25. package/dist/execute.js.map +1 -0
  26. package/dist/exports/types-deprecated.d.ts +62 -0
  27. package/dist/exports/types-deprecated.d.ts.map +1 -0
  28. package/dist/exports/types-deprecated.js +5 -0
  29. package/dist/exports/types-deprecated.js.map +1 -0
  30. package/dist/index.d.ts +9 -0
  31. package/dist/index.d.ts.map +1 -0
  32. package/dist/index.js +140 -0
  33. package/dist/index.js.map +1 -0
  34. package/dist/types.d.ts +162 -0
  35. package/dist/types.d.ts.map +1 -0
  36. package/dist/types.js +3 -0
  37. package/dist/types.js.map +1 -0
  38. package/package.json +88 -1
  39. package/.prettierignore +0 -12
  40. package/.swcrc +0 -24
  41. package/eslint.config.js +0 -18
  42. package/src/addresses/addressesCollection.ts +0 -76
  43. package/src/addresses/defaultAddressFields.ts +0 -83
  44. package/src/addresses/defaultCountries.ts +0 -50
  45. package/src/carts/beforeChange.ts +0 -51
  46. package/src/carts/cartsCollection.ts +0 -146
  47. package/src/currencies/index.ts +0 -29
  48. package/src/endpoints/confirmOrder.ts +0 -312
  49. package/src/endpoints/initiatePayment.ts +0 -322
  50. package/src/exports/addresses.ts +0 -2
  51. package/src/exports/currencies.ts +0 -1
  52. package/src/exports/fields.ts +0 -5
  53. package/src/exports/orders.ts +0 -1
  54. package/src/exports/payments/stripe.ts +0 -1
  55. package/src/exports/plugin.ts +0 -1
  56. package/src/exports/products.ts +0 -1
  57. package/src/exports/react.ts +0 -8
  58. package/src/exports/transactions.ts +0 -1
  59. package/src/exports/translations.ts +0 -1
  60. package/src/exports/types.ts +0 -7
  61. package/src/exports/ui.ts +0 -3
  62. package/src/exports/variants.ts +0 -5
  63. package/src/fields/amountField.ts +0 -43
  64. package/src/fields/cartItemsField.ts +0 -84
  65. package/src/fields/currencyField.ts +0 -39
  66. package/src/fields/inventoryField.ts +0 -22
  67. package/src/fields/pricesField.ts +0 -65
  68. package/src/fields/statusField.ts +0 -57
  69. package/src/fields/variantsFields.ts +0 -56
  70. package/src/index.ts +0 -275
  71. package/src/orders/ordersCollection.ts +0 -157
  72. package/src/payments/adapters/stripe/confirmOrder.ts +0 -123
  73. package/src/payments/adapters/stripe/endpoints/webhooks.ts +0 -69
  74. package/src/payments/adapters/stripe/index.ts +0 -135
  75. package/src/payments/adapters/stripe/initiatePayment.ts +0 -131
  76. package/src/products/productsCollection.ts +0 -78
  77. package/src/react/provider/index.tsx +0 -893
  78. package/src/react/provider/types.ts +0 -184
  79. package/src/react/provider/utilities.ts +0 -22
  80. package/src/transactions/transactionsCollection.ts +0 -166
  81. package/src/translations/en.ts +0 -64
  82. package/src/translations/index.ts +0 -11
  83. package/src/translations/translation-schema.json +0 -35
  84. package/src/types.ts +0 -403
  85. package/src/ui/PriceInput/FormattedInput.tsx +0 -134
  86. package/src/ui/PriceInput/index.scss +0 -28
  87. package/src/ui/PriceInput/index.tsx +0 -43
  88. package/src/ui/PriceInput/utilities.ts +0 -46
  89. package/src/ui/PriceRowLabel/index.css +0 -13
  90. package/src/ui/PriceRowLabel/index.tsx +0 -56
  91. package/src/ui/VariantOptionsSelector/ErrorBox.tsx +0 -27
  92. package/src/ui/VariantOptionsSelector/OptionsSelect.tsx +0 -78
  93. package/src/ui/VariantOptionsSelector/index.css +0 -37
  94. package/src/ui/VariantOptionsSelector/index.tsx +0 -83
  95. package/src/utilities/defaultProductsValidation.ts +0 -42
  96. package/src/utilities/errorCodes.ts +0 -14
  97. package/src/utilities/getCollectionSlugMap.ts +0 -84
  98. package/src/utilities/sanitizePluginConfig.ts +0 -80
  99. package/src/variants/variantOptionsCollection.ts +0 -59
  100. package/src/variants/variantTypesCollection.ts +0 -55
  101. package/src/variants/variantsCollection/hooks/beforeChange.ts +0 -47
  102. package/src/variants/variantsCollection/hooks/validateOptions.ts +0 -72
  103. package/src/variants/variantsCollection/index.ts +0 -119
  104. package/tsconfig.json +0 -7
  105. package/tsconfig.tsbuildinfo +0 -1
@@ -0,0 +1,162 @@
1
+ import type { ResultSet } from '@libsql/client';
2
+ import type { BuildQueryJoinAliases, DrizzleAdapter, extendDrizzleTable } from '@payloadcms/drizzle';
3
+ import type { BaseSQLiteAdapter, BaseSQLiteArgs } from '@payloadcms/drizzle/sqlite';
4
+ import type { DrizzleConfig, Relation, Relations, SQL } from 'drizzle-orm';
5
+ import type { AnyD1Database, DrizzleD1Database } from 'drizzle-orm/d1';
6
+ import type { LibSQLDatabase } from 'drizzle-orm/libsql';
7
+ import type { AnySQLiteColumn, SQLiteInsertOnConflictDoUpdateConfig, SQLiteTableWithColumns, SQLiteTransactionConfig } from 'drizzle-orm/sqlite-core';
8
+ import type { SQLiteRaw } from 'drizzle-orm/sqlite-core/query-builders/raw';
9
+ import type { Payload, PayloadRequest } from 'payload';
10
+ type SQLiteSchema = {
11
+ relations: Record<string, GenericRelation>;
12
+ tables: Record<string, SQLiteTableWithColumns<any>>;
13
+ };
14
+ type SQLiteSchemaHookArgs = {
15
+ extendTable: typeof extendDrizzleTable;
16
+ schema: SQLiteSchema;
17
+ };
18
+ export type SQLiteSchemaHook = (args: SQLiteSchemaHookArgs) => Promise<SQLiteSchema> | SQLiteSchema;
19
+ export type Args = {
20
+ binding: AnyD1Database;
21
+ } & BaseSQLiteArgs;
22
+ export type GenericColumns = {
23
+ [x: string]: AnySQLiteColumn;
24
+ };
25
+ export type GenericTable = SQLiteTableWithColumns<{
26
+ columns: GenericColumns;
27
+ dialect: string;
28
+ name: string;
29
+ schema: string;
30
+ }>;
31
+ export type GenericRelation = Relations<string, Record<string, Relation<string>>>;
32
+ export type CountDistinct = (args: {
33
+ db: LibSQLDatabase;
34
+ joins: BuildQueryJoinAliases;
35
+ tableName: string;
36
+ where: SQL;
37
+ }) => Promise<number>;
38
+ export type DeleteWhere = (args: {
39
+ db: LibSQLDatabase;
40
+ tableName: string;
41
+ where: SQL;
42
+ }) => Promise<void>;
43
+ export type DropDatabase = (args: {
44
+ adapter: SQLiteD1Adapter;
45
+ }) => Promise<void>;
46
+ export type Execute<T> = (args: {
47
+ db?: LibSQLDatabase;
48
+ drizzle?: LibSQLDatabase;
49
+ raw?: string;
50
+ sql?: SQL<unknown>;
51
+ }) => SQLiteRaw<Promise<T>> | SQLiteRaw<ResultSet>;
52
+ export type Insert = (args: {
53
+ db: LibSQLDatabase;
54
+ onConflictDoUpdate?: SQLiteInsertOnConflictDoUpdateConfig<any>;
55
+ tableName: string;
56
+ values: Record<string, unknown> | Record<string, unknown>[];
57
+ }) => Promise<Record<string, unknown>[]>;
58
+ type SQLiteDrizzleAdapter = Omit<DrizzleAdapter, 'countDistinct' | 'deleteWhere' | 'drizzle' | 'dropDatabase' | 'execute' | 'idType' | 'insert' | 'operators' | 'relations'>;
59
+ export interface GeneratedDatabaseSchema {
60
+ schemaUntyped: Record<string, unknown>;
61
+ }
62
+ type Drizzle = {
63
+ $client: AnyD1Database;
64
+ } & DrizzleD1Database<Record<string, any>>;
65
+ export type SQLiteD1Adapter = {
66
+ binding: Args['binding'];
67
+ client: AnyD1Database;
68
+ drizzle: Drizzle;
69
+ } & BaseSQLiteAdapter & SQLiteDrizzleAdapter;
70
+ export type IDType = 'integer' | 'numeric' | 'text';
71
+ export type MigrateUpArgs = {
72
+ /**
73
+ * The SQLite Drizzle instance that you can use to execute SQL directly within the current transaction.
74
+ * @example
75
+ * ```ts
76
+ * import { type MigrateUpArgs, sql } from '@payloadcms/db-sqlite'
77
+ *
78
+ * export async function up({ db, payload, req }: MigrateUpArgs): Promise<void> {
79
+ * const { rows: posts } = await db.run(sql`SELECT * FROM posts`)
80
+ * }
81
+ * ```
82
+ */
83
+ db: Drizzle;
84
+ /**
85
+ * The Payload instance that you can use to execute Local API methods
86
+ * To use the current transaction you must pass `req` to arguments
87
+ * @example
88
+ * ```ts
89
+ * import { type MigrateUpArgs } from '@payloadcms/db-sqlite'
90
+ *
91
+ * export async function up({ db, payload, req }: MigrateUpArgs): Promise<void> {
92
+ * const posts = await payload.find({ collection: 'posts', req })
93
+ * }
94
+ * ```
95
+ */
96
+ payload: Payload;
97
+ /**
98
+ * The `PayloadRequest` object that contains the current transaction
99
+ */
100
+ req: PayloadRequest;
101
+ };
102
+ export type MigrateDownArgs = {
103
+ /**
104
+ * The SQLite Drizzle instance that you can use to execute SQL directly within the current transaction.
105
+ * @example
106
+ * ```ts
107
+ * import { type MigrateDownArgs, sql } from '@payloadcms/db-sqlite'
108
+ *
109
+ * export async function down({ db, payload, req }: MigrateDownArgs): Promise<void> {
110
+ * const { rows: posts } = await db.run(sql`SELECT * FROM posts`)
111
+ * }
112
+ * ```
113
+ */
114
+ db: Drizzle;
115
+ /**
116
+ * The Payload instance that you can use to execute Local API methods
117
+ * To use the current transaction you must pass `req` to arguments
118
+ * @example
119
+ * ```ts
120
+ * import { type MigrateDownArgs } from '@payloadcms/db-sqlite'
121
+ *
122
+ * export async function down({ db, payload, req }: MigrateDownArgs): Promise<void> {
123
+ * const posts = await payload.find({ collection: 'posts', req })
124
+ * }
125
+ * ```
126
+ */
127
+ payload: Payload;
128
+ /**
129
+ * The `PayloadRequest` object that contains the current transaction
130
+ */
131
+ req: PayloadRequest;
132
+ };
133
+ declare module 'payload' {
134
+ interface DatabaseAdapter extends Omit<Args, 'idType' | 'logger' | 'migrationDir' | 'pool'>, DrizzleAdapter {
135
+ beginTransaction: (options?: SQLiteTransactionConfig) => Promise<null | number | string>;
136
+ drizzle: Drizzle;
137
+ /**
138
+ * 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
139
+ * Used for returning properly formed errors from unique fields
140
+ */
141
+ fieldConstraints: Record<string, Record<string, string>>;
142
+ idType: Args['idType'];
143
+ initializing: Promise<void>;
144
+ localesSuffix?: string;
145
+ logger: DrizzleConfig['logger'];
146
+ prodMigrations?: {
147
+ down: (args: MigrateDownArgs) => Promise<void>;
148
+ name: string;
149
+ up: (args: MigrateUpArgs) => Promise<void>;
150
+ }[];
151
+ push: boolean;
152
+ rejectInitializing: () => void;
153
+ relationshipsSuffix?: string;
154
+ resolveInitializing: () => void;
155
+ schema: Record<string, GenericRelation | GenericTable>;
156
+ tableNameMap: Map<string, string>;
157
+ transactionOptions: SQLiteTransactionConfig;
158
+ versionsSuffix?: string;
159
+ }
160
+ }
161
+ export {};
162
+ //# 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,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,KAAK,EAAE,qBAAqB,EAAE,cAAc,EAAE,kBAAkB,EA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AQ,GAAG,cAAc,GAAG,MAAM,CAAC,EAC/D,cAAc;QAChB,gBAAgB,EAAE,CAAC,OAAO,CAAC,EAAE,uBAAuB,KAAK,OAAO,CAAC,IAAI,GAAG,MAAM,GAAG,MAAM,CAAC,CAAA;QACxF,OAAO,EAAE,OAAO,CAAA;QAChB;;;WAGG;QACH,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;QACxD,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAA;QACtB,YAAY,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;QAC3B,aAAa,CAAC,EAAE,MAAM,CAAA;QACtB,MAAM,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAA;QAC/B,cAAc,CAAC,EAAE;YACf,IAAI,EAAE,CAAC,IAAI,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;YAC9C,IAAI,EAAE,MAAM,CAAA;YACZ,EAAE,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;SAC3C,EAAE,CAAA;QACH,IAAI,EAAE,OAAO,CAAA;QACb,kBAAkB,EAAE,MAAM,IAAI,CAAA;QAC9B,mBAAmB,CAAC,EAAE,MAAM,CAAA;QAC5B,mBAAmB,EAAE,MAAM,IAAI,CAAA;QAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,GAAG,YAAY,CAAC,CAAA;QACtD,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QACjC,kBAAkB,EAAE,uBAAuB,CAAA;QAC3C,cAAc,CAAC,EAAE,MAAM,CAAA;KACxB;CACF"}
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ export { };
2
+
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { ResultSet } from '@libsql/client'\nimport type { BuildQueryJoinAliases, DrizzleAdapter, extendDrizzleTable } from '@payloadcms/drizzle'\nimport type { BaseSQLiteAdapter, BaseSQLiteArgs } from '@payloadcms/drizzle/sqlite'\nimport type { DrizzleConfig, Relation, Relations, SQL } from 'drizzle-orm'\nimport type { AnyD1Database, 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: AnyD1Database\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: AnyD1Database } & DrizzleD1Database<Record<string, any>>\n\nexport type SQLiteD1Adapter = {\n binding: Args['binding']\n client: AnyD1Database\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":[],"mappings":"AAyIA,WA8BC"}
package/package.json CHANGED
@@ -1,4 +1,91 @@
1
1
  {
2
2
  "name": "@payloadcms/db-d1-sqlite",
3
- "version": "0.0.1-beta.0"
3
+ "version": "3.58.0-canary.4",
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
+ },
58
+ "main": "./dist/index.js",
59
+ "types": "./dist/index.d.ts",
60
+ "files": [
61
+ "dist",
62
+ "mock.js"
63
+ ],
64
+ "dependencies": {
65
+ "console-table-printer": "2.12.1",
66
+ "drizzle-kit": "0.31.4",
67
+ "drizzle-orm": "0.44.2",
68
+ "prompts": "2.4.2",
69
+ "to-snake-case": "1.0.0",
70
+ "uuid": "9.0.0",
71
+ "@payloadcms/drizzle": "3.58.0-canary.4"
72
+ },
73
+ "devDependencies": {
74
+ "@types/pg": "8.10.2",
75
+ "@types/to-snake-case": "1.0.0",
76
+ "@types/uuid": "10.0.0",
77
+ "@payloadcms/eslint-config": "3.28.0",
78
+ "payload": "3.58.0-canary.4"
79
+ },
80
+ "peerDependencies": {
81
+ "payload": "3.58.0-canary.4"
82
+ },
83
+ "scripts": {
84
+ "build": "pnpm build:swc && pnpm build:types",
85
+ "build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths",
86
+ "build:types": "tsc --emitDeclarationOnly --outDir dist",
87
+ "clean": "rimraf -g {dist,*.tsbuildinfo}",
88
+ "lint": "eslint .",
89
+ "lint:fix": "eslint . --fix"
90
+ }
4
91
  }
package/.prettierignore DELETED
@@ -1,12 +0,0 @@
1
- .tmp
2
- **/.git
3
- **/.hg
4
- **/.pnp.*
5
- **/.svn
6
- **/.yarn/**
7
- **/build
8
- **/dist/**
9
- **/node_modules
10
- **/temp
11
- **/docs/**
12
- tsconfig.json
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
- }