gitoria

components

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit3d43c1873d43c187ident-access: server-side check of an ident access key (Bearer or Basic password), asks ident on every call, README, gate tests/ident-access.mjs (ident#27 app side)mre3d43c187/plugins/mpackdb/MPackDB.hl

4.9 KB

  1. \* hl:mpackdb — the MessagePack file database. Construct it and it opens
  2. (the file root IS the constructor):
  3. db = new MPackDB(file = '/tmp/users.db', primaryKey = '*id',
  4. indexes = ['!email', 'age'])
  5. Key prefixes follow the JS API: `*name` auto-increment number pk (a fresh
  6. table counts from 1; an existing one keeps its stored counter), `@name`
  7. uuid pk, plain `name` string pk; a LEADING `!` on an index makes it
  8. unique, `*`/`@` on an index select numeric/uuid key parsing. On-disk
  9. format is compatible with the JS mpackdb 1.0.7 — a db written by either
  10. side is readable and mutable by the other. *\
  11. /* Wraps the Zig engine (plugins/mpackdb/{msgpack,engine}.zig, mission 066).
  12. `>` / `<>` hydration does NOT run the run body — construct with args. */
  13. \* The database is open (fired from the constructor's run body). *\
  14. emit opened(
  15. MPackDB db \\ this database
  16. )
  17. \* Opening failed. *\
  18. emit error(
  19. Hybrid e \\ the failure
  20. )
  21. \* close() finished. *\
  22. emit closed(
  23. MPackDB db \\ this database
  24. )
  25. String file = "" \\ the .db path, script-relative
  26. String primaryKey = "" \\ pk declaration: *name | @name | name | '' for none
  27. Hybrid indexes = [] \\ index declarations, '!' prefix = unique
  28. Boolean compact = true \\ compact the file on open
  29. Hybrid #handle
  30. Boolean #warned = false \\ find(null, null) over a big table was reported on stderr already
  31. String #pk \\ the primary key FIELD NAME, prefixes stripped (null when none)
  32. open() {
  33. #handle = __native("mpackdb.open", file, primaryKey, indexes, compact)
  34. if (#handle != null) {
  35. #pk = #handle.pk_name()
  36. emit opened(this)
  37. } else {
  38. emit error(new Error("mpackdb: cannot open " + file))
  39. }
  40. }
  41. open()
  42. \* The primary key field name, prefixes stripped (null when none). *\
  43. pkField() {
  44. return #pk
  45. }
  46. \* Insert one record. Answers the primary key it was stored under (a
  47. generated one for `*`/`@` pks), true for a pk-less db, or null on failure
  48. — lastError() has the reason (e.g. a unique-index violation). *\
  49. put(
  50. Hybrid record \\ the record to store
  51. ) {
  52. return #handle.insert(record)
  53. }
  54. \* First record with this primary key, or null. (Named fetch(), not get():
  55. `get` is reserved for getter syntax.) *\
  56. fetch(key) {
  57. let it = #handle.find_pk(key)
  58. if (it == null) {
  59. return null
  60. }
  61. let first = it.next()
  62. // run it to its end: the plugin frees what the lookup read there (hybriel#126)
  63. while (it.next() != null) {}
  64. return first
  65. }
  66. \* Raw iterator over matches. field null → every live record; the pk and any
  67. declared index are binary-searched — other fields need an index declared. *\
  68. iterate(field, value) {
  69. if (field == null) {
  70. return #handle.find_all()
  71. }
  72. if (field == #pk) {
  73. return #handle.find_pk(value)
  74. }
  75. return #handle.find_index(field, value)
  76. }
  77. \* All matching records as a Hybrid; find(null) answers everything. find(null, null) over more than
  78. 100 000 records prints ONE line per table on stderr (the array holds the whole table decoded:
  79. use iterate() or cursor()); the result is the same. *\
  80. find(field, value) {
  81. let out = drain(iterate(field, value))
  82. if (field == null && value == null && out.length > 100000 && !#warned) {
  83. // one line per table: a whole big table decoded into one array holds ~27x its file in RAM
  84. #warned = true
  85. console.error("mpackdb: " + file + ": find(null, null) built an array of " + out.length + " records; use iterate()")
  86. }
  87. return out
  88. }
  89. \* Ascending index range scan, both bounds inclusive; null bound = open end. *\
  90. range(field, low, high) {
  91. return drain(#handle.find_range(field, low, high))
  92. }
  93. \* Lazy Cursor over the same matches — records decode one at a time. *\
  94. cursor(field, value) {
  95. return {
  96. #iter = iterate(field, value);
  97. } > new Cursor()
  98. }
  99. \* Delete every record with this primary key; answers how many went. *\
  100. delete(key) {
  101. return #handle.delete_pk(key)
  102. }
  103. \* Replace the record(s) at this pk; answers how many were replaced. `record`
  104. need not carry the pk: it is taken from `key` (the JS update() contract). *\
  105. update(key, record) {
  106. return #handle.update_pk(key, record)
  107. }
  108. \* Live record count. *\
  109. count() {
  110. return #handle.count()
  111. }
  112. \* Rewrite the data file without tombstones and rebuild the indexes. *\
  113. compactNow() {
  114. #handle.compact()
  115. }
  116. \* Cursors made by any db of this process that are neither exhausted nor closed
  117. (a `for` loop left by break/return closes its cursor at once; mission 404). *\
  118. openCursors() {
  119. return #handle.open_cursors()
  120. }
  121. \* How many cursors a `for` loop closed by leaving early (break/return). *\
  122. earlyCloses() {
  123. return #handle.early_closes()
  124. }
  125. \* Flush meta/index state to disk now. *\
  126. persist() {
  127. #handle.persist()
  128. }
  129. \* Reason for the last failed put/update ('' when none). *\
  130. lastError() {
  131. return #handle.last_error()
  132. }
  133. \* Close the database; the closed event fires. *\
  134. close() {
  135. #handle.close()
  136. emit closed(this)
  137. }
  138. // Internal: collect an iterator into an array.
  139. drain(it) {
  140. let out = []
  141. if (it == null) {
  142. return out
  143. }
  144. for (rec of it) {
  145. out.push(rec)
  146. }
  147. return out
  148. }

Branches

Latest commits

  • 3d43c187ident-access: server-side check of an ident access key (Bearer or Basic password), asks ident on every call, README, gate tests/ident-access.mjs (ident#27 app side)mre
  • 59704ce1Merge branch 'n5b-pipes'mre
  • 23b9164aMdEditor: a clipboard whose text is only the names or file:// paths of its files (a file manager copy) is about the files, as before; any other text wins (tickets#49); gate casesmre
  • b0f1ec28MdEditor: a clipboard with text always pastes the text, also when a picture is on it too (a spreadsheet or office app), files on or off; a picture alone still goes to the files; real Ctrl+V gate tests/md-paste-files.mjs (tickets#49)mre
  • ad4e929bMdEditor: pipe rows without a delimiter row are a table (first row = header, short rows padded, written back without an invented | --- | line) (notes#5)mre
  • 4bd11128MdEditor: the Table button's empty table is written as a real pipe table (empty cells), so it survives the source switch, a save and a reload (notes#7)mre
  • 7437e32bMdEditor draws its surface at once when claimed from server HTML: 1 ms mount animation, the first editor mounts all editors of the pagemre
  • 5de0264cRe-vendor onto Hybriel master acaceaf3 (set-day27b): binary, lib and plugins; exit 1 on a startup fault; .gitignore binmre
  • 79c77e7dMerge sb3-standby: components deploys through its standbymre
  • c5442043components: no jobs switch needed in the standbymre
  • 8d2fb24ccomponents: a standby container (port 45016, profile standby); deploy hands over through standby-swap.sh without a gapmre
  • c2834dd3Merge mr-fixes: media player state after a queue pick, Range handling, cover-less audio, accessibility labelsmre
  • 354fe3c6Media player: audio without a cover starts and shows its time (the mount tick sits on the seek bar, which every item has); the speed button names the current speed, the seek slider says its time in words; a gate page for the first render on cover-less audio and a fourth demo queue item without a covermre
  • ee4aee1eMedia player: a new queue item shows its own speed, mute, play state and time and starts when asked, also for two videos in a row; the media route reads suffix ranges and ignores range lists and garbage instead of answering 500; stronger gate checks (the 10 percent drag, the played bar, the queue tap)mre
  • 9a4f9b31Merge mp-player: media served from the committed filesmre
  • ab96e686Media route: serve the demo's media from the committed files in components/media-player (storage/ is not in git, the deploy gate found no files)mre
  • b2980734Merge mp-player: the media player (components/media-player), its demo and the media iconsmre
  • 1c41293eMediaPlayer: back / forward 10 s as replay / forward 10 icons (circular arrow with a 10), the play button keeps its surface background on audio and video, the media route's range end is a letmre
  • 9e1ab228MP: report, LOG line, STATUS entrymre
  • dd003e5dMediaPlayer: audio and video in one phone-first player (components/media-player), its demo /media-player with a queue, the media icons in components/icons, the demo's media files served with ranges (lib/media.hl), 35 gate checksmre