{"_id":"@bluaxolotl/sequelize-browser","name":"@bluaxolotl/sequelize-browser","dist-tags":{"latest":"6.1.3"},"versions":{"6.1.3":{"name":"@bluaxolotl/sequelize-browser","version":"6.1.3","description":"Fork of 'https://gitlab.com/catamphetamine/sequelize-browser.git' that uses @bluaxolotl/sequelize","module":"sequelize.js","main":"sequelize.cjs","types":"./index.d.ts","type":"module","exports":{".":{"types":"./index.d.ts","import":"./sequelize.js","require":"./sequelize.cjs"},"./build":{"types":"./build/index.d.ts","import":"./build/index.js","require":"./build/index.cjs"},"./package.json":"./package.json"},"sideEffects":false,"bin":{"sequelize-browser":"runnable/sequelize-browser.js"},"scripts":{"test":"mocha --colors --bail --reporter spec \"./{,!(node_modules|commonjs|modules)/**/}*.test.js\" --recursive","clean-for-build":"rimraf ./commonjs/**/* ./modules/**/*","build-commonjs-modules":"cross-env BABEL_ENV=commonjs babel ./source --out-dir ./commonjs --source-maps","build-commonjs-package.json":"node runnable/create-commonjs-package-json.js","build-commonjs":"npm-run-all build-commonjs-modules build-commonjs-package.json","build-es6-modules":"cross-env BABEL_ENV=es6 babel ./source --out-dir ./modules --source-maps","build-build":"node build.default.js","build-website":"cpy sequelize.script.js sequelize.script.js.map website/lib --flat","build":"npm-run-all clean-for-build create-validator-shim build-commonjs build-es6-modules update-sequelize update-validator build-build build-website","update-sequelize":"yarn add sequelize@npm:@bluaxolotl/sequelize@latest --dev","update-validator":"yarn upgrade sequelize@npm:@bluaxolotl/sequelize","create-validator-shim":"node runnable/create-validator-shim.js","prepublishOnly":"npm-run-all build test"},"peerDependencies":{"sequelize":"npm:@bluaxolotl/sequelize@^6.37.4"},"devDependencies":{"@babel/cli":"^7.17.10","@babel/core":"^7.17.12","@babel/plugin-proposal-class-properties":"^7.17.12","@babel/plugin-transform-for-of":"^7.17.12","@babel/plugin-transform-runtime":"^7.17.12","@babel/preset-env":"^7.17.12","chai":"^4.3.6","cpy-cli":"^5.0.0","cross-env":"^7.0.3","mocha":"^10.0.0","npm-run-all":"^4.1.5","rimraf":"^3.0.2","sequelize":"npm:@bluaxolotl/sequelize","sql.js":"^1.10.2","sql.js-as-sqlite3":"^0.2.0"},"repository":{"type":"git","url":"git+https://github.com/planet-bluto/sequelize-browser.git"},"keywords":["sequelize","browser","web","bundle"],"author":{"name":"catamphetamine","email":"purecatamphetamine@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/planet-bluto/sequelize-browser/issues"},"homepage":"https://github.com/planet-bluto/sequelize-browser#readme","dependencies":{"buffer":"^6.0.3","esbuild":"^0.18.10","format-util":"^1.0.5","minimist":"^1.2.8","qs":"^6.11.2","util-deprecate":"^1.0.2","validator":"^13.9.0"},"_id":"@bluaxolotl/sequelize-browser@6.1.3","gitHead":"18aaf33f22af4ef77bb2a2d73f1e242c89421c9c","_nodeVersion":"20.17.0","_npmVersion":"10.8.2","dist":{"integrity":"sha512-YamwllWZAgEKYE/Yb4ImXS7qI6NJKN4rV60OG+2lxQY9JApqo87JYNbxV72VnYKlOnq2IRtovdzKyaH0kCJ3/g==","shasum":"bc17e183ae40fe56c8fe308cc000317e521aecae","tarball":"https://registry.npmjs.org/@bluaxolotl/sequelize-browser/-/sequelize-browser-6.1.3.tgz","fileCount":212,"unpackedSize":24683726,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCvrx45YjbW5CjFjLk2V1XdxQB2R4ZmirZ0UoCx7QyD1wIhAKODkRlBXTm//HcPGLNe1+xQ4uKfjPhgaGO/MWz1kYnQ"}]},"_npmUser":{"name":"bluaxolotl","email":"plush.gamer.456@gmail.com"},"directories":{},"maintainers":[{"name":"bluaxolotl","email":"plush.gamer.456@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/sequelize-browser_6.1.3_1727181366700_0.9891645646864986"},"_hasShrinkwrap":false}},"time":{"created":"2024-09-24T12:36:06.601Z","6.1.3":"2024-09-24T12:36:06.925Z","modified":"2024-09-24T12:36:07.183Z"},"maintainers":[{"name":"bluaxolotl","email":"plush.gamer.456@gmail.com"}],"description":"Fork of 'https://gitlab.com/catamphetamine/sequelize-browser.git' that uses @bluaxolotl/sequelize","homepage":"https://github.com/planet-bluto/sequelize-browser#readme","keywords":["sequelize","browser","web","bundle"],"repository":{"type":"git","url":"git+https://github.com/planet-bluto/sequelize-browser.git"},"author":{"name":"catamphetamine","email":"purecatamphetamine@gmail.com"},"bugs":{"url":"https://github.com/planet-bluto/sequelize-browser/issues"},"license":"MIT","readme":"# `sequelize-browser`\n\nA build of [Sequelize](https://sequelize.org/) that runs in a web browser.\n\n[Demo](https://catamphetamine.github.io/sequelize-browser/)\n\n<!-- https://catamphetamine.gitlab.io/sequelize-browser/ -->\n\n## Install\n\n```\nnpm install sequelize-browser --save\n```\n\n## Use\n\nThere're two ways of using this package:\n* The most simple way would be using the [default build](#default-build) that was created from the latest version of Sequelize at the time of publishing this package.\n* The \"advanced\" way would be creating a [custom build](#custom-build) for a particular version of Sequelize.\n\n### Default Build\n\nA pre-made build of `sequelize@6` is available as part of this package.\n\nThe files are:\n\n* `sequelize.js` — A non-\"minified\" \"ES6\" version of the build. It can be `import`ed when using a bundler such as Webpack.\n* `sequelize.cjs` — A non-\"minified\" \"CommonJS\" version of the build. It can be `require()`d when using a bundler such as Webpack.\n* `sequelize.script.js` — A \"minified\" \"bundled\" build for including it on a web page via a `<script/>` tag. Sequelize will be available as `Sequelize` global variable.\n\nUse it either way:\n\n```js\nimport Sequelize from 'sequelize-browser'\n```\n\n```js\nconst Sequelize = require('sequelize-browser')\n```\n\n```html\n<script src=\"https://unpkg.com/sequelize-browser@6.x/sequelize.script.js\"></script>\n\n<script>\n  console.log(Sequelize)\n</script>\n```\n\n### Custom Build\n\nTo create a custom build from a particular version of Sequelize, first install that particular version of Sequelize:\n\n```\nnpm install sequelize@6.x.y\n```\n\nAfter that, either use the [command-line](#command-line) way of running the build via `npx` command or use a [programmatic](#programmatic) way of running the build via `sequelize-browser/build` export.\n\n#### Command Line\n\nFirst, install [`npx`](https://www.npmjs.com/package/npx) if it's not already installed in your system:\n\n```\nnpm install -g npx\n```\n\nThen, run the build command:\n\n```\nnpx sequelize-browser \\\n  --input ./node_modules/sequelize \\\n  --output ./output/sequelize.js \\\n  --dialects sqlite,mysql\n  --format iife \\\n  --minify true\n```\n\n#### Programmatic\n\n```js\nimport build from 'sequelize-browser/build'\n\nawait build({\n  // Path to the installed version of Sequelize.\n  input: './node_modules/sequelize',\n  // Path to the output file.\n  output: './output/sequelize.js',\n  // Supported \"dialects\".\n  dialects: ['sqlite'],\n  // * \"esm\" — For including the resulting file via `import`.\n  // * \"cjs\" — For including the resulting file via `require()`.\n  // * \"iife\" — For including the resulting file directly via a \"<script/>\" tag on a page.\n  format: 'iife',\n  // Whether it should \"minify\" the code.\n  minify: true\n})\n```\n\n## Databases\n\nThe following databases have been tested and appear to be working:\n\n* SQLite — with `sqlite` \"dialect\" and [`sql.js-as-sqlite3`](https://npmjs.com/package/sql.js-as-sqlite3) package as a `dialectModule` parameter value.\n\n### Node.js\n\n```js\nimport Sequelize from 'sequelize'\nimport sqlJsAsSqlite3 from 'sql.js-as-sqlite3'\n\nconst sequelize = new Sequelize('sqlite://:memory:', {\n  dialectModule: sqlJsAsSqlite3\n})\n```\n\n### Browser (with bundler)\n\n```js\nimport Sequelize from 'sequelize'\nimport sqlJsAsSqlite3 from 'sql.js-as-sqlite3'\nimport initSqlJs from 'sql.js'\n\nsqlJsAsSqlite3.configure({\n  // `sql.js` package default export.\n  initSqlJs,\n  // Base URL for `sql.js` to get the `*.wasm` files like `sql-wasm-debug.wasm`.\n  // The version of the `*.wasm` files must match the version of the `sql.js` package.\n  // Must end with a \"/\".\n  wasmFileBaseUrl: 'https://cdnjs.cloudflare.com/ajax/libs/sql.js/1.10.2/'\n})\n\nconst sequelize = new Sequelize('sqlite://:memory:', {\n  dialectModule: sqlJsAsSqlite3\n})\n```\n\n### Browser (no bundler)\n\nOne can use any npm CDN service, e.g. [unpkg.com](https://unpkg.com) or [jsdelivr.net](https://jsdelivr.net)\n\n```html\n<script src=\"https://unpkg.com/sequelize-browser@6.x/sequelize.script.js\"></script>\n\n<script src=\"https://unpkg.com/sql.js-as-sqlite3@0.2.x/bundle/sql.js-as-sqlite3.min.js\"></script>\n\n<script src=\"https://cdnjs.cloudflare.com/ajax/libs/sql.js/1.10.2/sql-wasm.min.js\"></script>\n<script>\n  // Base URL for `sql.js` to get the `*.wasm` files like `sql-wasm-debug.wasm`.\n  // The version of the `*.wasm` files must match the version of `sql.js`.\n  // Must end with a \"/\".\n  SQL_JS_WASM_FILE_BASE_URL = 'https://cdnjs.cloudflare.com/ajax/libs/sql.js/1.10.2/'\n</script>\n\n<script>\n  const sequelize = new Sequelize('sqlite://:memory:', {\n    dialectModule: sqlJsAsSqlite3\n  })\n</script>\n```\n\n## Limitations\n\n### Transactions\n\n(Advanced Feature) When creating [\"managed\" transactions](https://sequelize.org/docs/v6/other-topics/transactions/) via `sequelize.transaction(options, callback)`, it utilizes the \"CLS\" (Continuation Local Storage) feature of Node.js to automatically (or rather \"automagically\") select that transaction for any queries dispatched from the `callback`.\n\n```js\nawait sequelize.transaction(async () => {\n  // This `.create()` call will be executed inside the transaction.\n  const user = await User.create({\n    firstName: 'Abraham',\n    lastName: 'Lincoln'\n  });\n});\n```\n\nWhen running in a web browser, that magic of Node.js is not available, so a developer will have to explicitly specify the transaction for queries dispatched from the `callback`.\n\n```js\nawait sequelize.transaction(async t => {\n  const user = await User.create({\n    firstName: 'Abraham',\n    lastName: 'Lincoln'\n  }, { transaction: t });\n});\n```\n\n### Validator\n\nBy default, Sequelize [supports](https://sequelize.org/docs/v6/core-concepts/validations-and-constraints/#per-attribute-validations) specifying \"validators\" from [`validator.js`](https://github.com/validatorjs/validator.js) library on a model field.\n\n```js\nsequelize.define('modelName', {\n  fieldName: {\n    type: DataTypes.STRING,\n    validate: {\n      isPostalCode: true, // Implicitly calls `isPostalCode(value)` function from `validator.js` library.\n      isUppercase: true   // Implicitly calls `isUppercase(value)` function from `validator.js` library.\n    }\n  }\n})\n```\n\nHowever, while being convenient, including the whole `validator.js` package in the bundle just to support that feature increases its size by about `100 KB`, which looks like an overkill provided that most people don't even use this feature, or maybe only use a few of the \"validators\" from the (long) list.\n\nSo to reduce the overall bundle size, and to decouple `sequelize` itself from `validator.js` package, the feature was removed. When attempting to call a certain function of `validator.js`, it will throw an error like:\n\n> `isPostalCode` function from `validator` package is not included in a browser version of `sequelize`. To fix this, import the `isPostalCode` function from `validator` package manually and then either (a) use it in a field's `validate` or (b) set it on the `Sequelize.Validator` object.\n\nAs the error message suggests, there're two simple ways to fix it.\n\nThe first way would be `import`ing the relevant \"validator\" functions from `validator.js` and then using them in the `validate` map of a model field.\n\n```js\nimport isPostalCode from 'validator/lib/isPostalCode'\nimport isUppercase from 'validator/lib/isUppercase'\n\nsequelize.define('modelName', {\n  fieldName: {\n    type: DataTypes.STRING,\n    validate: {\n      isPostalCode: value => isPostalCode(value),\n      isUppercase: value => isUppercase(value)\n    }\n  }\n})\n```\n\nThe second way would be `import`ing the relevant \"validator\" functions from `validator.js` and then setting them on the `Sequelize.Validator` object.\n\n```js\nimport isPostalCode from 'validator/lib/isPostalCode'\nimport isUppercase from 'validator/lib/isUppercase'\n\nSequelize.Validator.isPostalCode = isPostalCode\nSequelize.Validator.isUppercase = isUppercase\n```\n\n### Bundle Size\n\nThe bundle size is currently at about `1.5 MB`.\n\n  * (resolved in `sequelize@7` code) Half of that is `moment`'s timezone data. The latest code in the `sequelize` repo seems to have [replaced](https://github.com/sequelize/sequelize/pull/16222) `moment` with `dayjs` which means that in the next \"major\" release of `sequelize` the browser bundle will be much smaller.\n    * After `sequelize@7` is published, uncomment `moment` \"shim\" in `source/aliases.js` and rebuild the package.\n\n  * (resolved in `sequelize@7` code) In the current version of `sequelize`, `validator` is imported as a whole instead of only the functions being used, which is about `115 KB` of the bundle size. [Reducing the scope](https://github.com/sequelize/sequelize/pull/16222#issuecomment-1615975113) of the functions imported from `validator`  would reduce the bundle size by a tiny bit. See the [discussion](https://github.com/sequelize/sequelize/issues/16223).\n    * After `sequelize@7` is published, uncomment `validator` \"shim\" in `source/aliases.js` and rebuild the package.\n\n  * (resolved in `sequelize@7` code) In the current version of `sequelize`, `lodash` is imported as a whole instead of only the functions being used, which is about `75 KB` of the bundle size. [Reducing the scope](https://github.com/sequelize/sequelize/pull/16222) of the functions imported from `lodash` could reduce the bundle size by a tiny bit, although negligibly.\n    * After `sequelize@7` is published, this is supposed to no longer be an issue.\n\nTo get more insight on what exactly occupies which part of the bundle, use the `sequelize.script.js.meta.json` file in the root of the package with a bundle analyzer:\n  * https://bundle-buddy.com\n  * https://esbuild.github.io/analyze\n\n## Sequelize\n\nA [pull request](https://github.com/sequelize/sequelize/pull/16208) was submitted to the original `sequelize` package repo, although the maintainers of the original package [preferred](https://github.com/sequelize/sequelize/pull/16208#issuecomment-1613288150) not to include it and instead would prefer to follow a more radical approach with rewriting the entire `sequelize` codebase in a more modern way, resolving any web browser incompatibilities in the process. Although I'd imagine such a large rewrite could potentially require an equally large amount of time, but at the same time this feature is more of a for-fun thing rather than some critical piece of functionality. Anyway, in the end, a decision was made to release this browser build of Sequelize as a standalone third-party package, so here it is. It also provides the commands to manually run the build from the original `sequelize` package so that any developer could easily create a browser-compatible build for any version of sequelize. For reference, here's the original [discussion](https://github.com/sequelize/sequelize/issues/16207).\n\n## GitHub\n\nOn March 9th, 2020, GitHub, Inc. silently [banned](https://medium.com/@catamphetamine/how-github-blocked-me-and-all-my-libraries-c32c61f061d3) my account (erasing all my repos, issues and comments, even in my employer's private repos) without any notice or explanation. Because of that, all source codes had to be promptly moved to GitLab. The [GitHub repo](https://github.com/catamphetamine/sequelize-browser) is now only used as a backup (you can star the repo there too), and the primary repo is now the [GitLab one](https://gitlab.com/catamphetamine/sequelize-browser). Issues can be reported in any repo.\n\n## License\n\n[MIT](LICENSE)\n\n","readmeFilename":"README.md"}