exports.id = 5016;
exports.ids = [5016];
exports.modules = {

/***/ 977844:
/***/ ((__unused_webpack_module, exports) => {

"use strict";

/*
 *  This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
 *  License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
 */
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.COMPUTE_STATES = void 0;
exports.COMPUTE_STATES = {
    archived: {
        desc: "Project is stored in longterm storage, and will take even longer to start.",
        icon: "file-archive",
        display: "Archived",
        stable: true,
        to: {
            closed: "unarchiving",
        },
        commands: ["unarchive"],
    },
    unarchiving: {
        desc: "Project is being copied from longterm storage; this may take several minutes depending on how many files you have.",
        icon: "download",
        display: "Unarchiving",
        to: {},
        timeout: 30 * 60,
        commands: ["status", "mintime"],
    },
    archiving: {
        desc: "Project is being moved to longterm storage.",
        icon: "paper-plane",
        display: "Archiving",
        to: {},
        timeout: 5 * 60,
        commands: ["status", "mintime"],
    },
    closed: {
        desc: "Project is stored only as ZFS streams, which must be imported, so it will take longer to start.",
        icon: "file-archive",
        display: "Closed",
        stable: true,
        to: {
            open: "opening",
            archived: "archiving",
        },
        commands: ["open", "move", "status", "destroy", "mintime", "archive"],
    },
    opening: {
        desc: "Project is being imported; this may take several minutes depending on size and history.",
        icon: "gears",
        display: "Opening",
        to: {},
        timeout: 30 * 60,
        commands: ["status", "mintime"],
    },
    closing: {
        desc: "Project is in the process of being closed.",
        icon: "download",
        display: "Closing",
        to: {},
        timeout: 5 * 60,
        commands: ["status", "mintime"],
    },
    opened: {
        desc: "Project is available and ready to try to run.",
        icon: "stop",
        display: "Stopped",
        stable: true,
        to: {
            start: "starting",
            close: "closing",
        },
        commands: [
            "start",
            "close",
            "save",
            "copy_path",
            "mkdir",
            "directory_listing",
            "read_file",
            "network",
            "mintime",
            "disk_quota",
            "compute_quota",
            "status",
            "migrate_live",
            "ephemeral_state",
            "ephemeral_disk",
        ],
    },
    pending: {
        desc_cocalccom: "Finding a place to run your project.  If nothing becomes available, reduce dedicated RAM or CPU, pay for members only hosting, or contact support.",
        desc: "Finding a place to run your project. If nothing becomes available, contact support.",
        icon: "times-rectangle",
        display: "Pending",
        stable: true,
        to: {
            stop: "stopping",
        },
        commands: ["stop"],
    },
    starting: {
        desc: "Project is starting up.",
        icon: "flash",
        display: "Starting",
        to: {},
        timeout: 60,
        commands: [
            "save",
            "copy_path",
            "mkdir",
            "directory_listing",
            "read_file",
            "network",
            "mintime",
            "disk_quota",
            "compute_quota",
            "status",
        ],
    },
    stopping: {
        desc: "Project is stopping.",
        icon: "hand-stop",
        display: "Stopping",
        timeout: 60,
        to: {},
        commands: [
            "save",
            "copy_path",
            "mkdir",
            "directory_listing",
            "read_file",
            "network",
            "mintime",
            "disk_quota",
            "compute_quota",
            "status",
        ],
    },
    running: {
        desc: "Project is running.",
        icon: "run",
        display: "Running",
        stable: true,
        to: {
            stop: "stopping",
        },
        commands: [
            "stop",
            "save",
            "address",
            "copy_path",
            "mkdir",
            "directory_listing",
            "read_file",
            "network",
            "mintime",
            "disk_quota",
            "compute_quota",
            "status",
            "migrate_live",
        ],
    },
};
//# sourceMappingURL=compute-states.js.map

/***/ }),

/***/ 799198:
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {

"use strict";

/*
 *  This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
 *  License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
 */
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.DEFAULT_QUOTAS = exports.RECENT_TIMES_KEY = exports.RECENT_TIMES = void 0;
// This file is purely to give HtmlWebpackPlugin an opportunity to pick up these const values
// In any other place, import from the main schema file
// these times in minutes are used for active/recently edited projects and accounts in postgres-server-queries.coffee's get_stats
exports.RECENT_TIMES = Object.freeze({
    active: 5,
    last_hour: 60,
    last_day: 60 * 24,
    last_week: 60 * 24 * 7,
    last_month: 60 * 24 * 30,
});
// this translates the semantic meanings to the keys used in the DB, also prevents typos!
exports.RECENT_TIMES_KEY = Object.freeze({
    active: "5min",
    last_hour: "1h",
    last_day: "1d",
    last_week: "7d",
    last_month: "30d",
});
var upgrade_spec_1 = __webpack_require__(292148);
Object.defineProperty(exports, "DEFAULT_QUOTAS", ({ enumerable: true, get: function () { return upgrade_spec_1.DEFAULT_QUOTAS; } }));
//# sourceMappingURL=schema-static.js.map

/***/ }),

/***/ 47896:
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {

"use strict";

/*
 *  This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
 *  License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
 */
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.UPGRADES_CURRENT_DATE = exports.DEFAULT_QUOTAS = exports.PROJECT_UPGRADES = exports.COMPUTE_STATES = exports.site_settings_conf = exports.client_db = exports.SCHEMA = exports.RECENT_TIMES_KEY = exports.RECENT_TIMES = void 0;
// RECENT_TIMES = these times in minutes are used for active/recently edited
// projects and accounts in postgres-server-queries.coffee's get_stats.
// This translates the semantic meanings to the keys used in the DB, also
// prevents typos!
var schema_static_1 = __webpack_require__(799198);
Object.defineProperty(exports, "RECENT_TIMES", ({ enumerable: true, get: function () { return schema_static_1.RECENT_TIMES; } }));
Object.defineProperty(exports, "RECENT_TIMES_KEY", ({ enumerable: true, get: function () { return schema_static_1.RECENT_TIMES_KEY; } }));
var db_schema_1 = __webpack_require__(98416);
Object.defineProperty(exports, "SCHEMA", ({ enumerable: true, get: function () { return db_schema_1.SCHEMA; } }));
Object.defineProperty(exports, "client_db", ({ enumerable: true, get: function () { return db_schema_1.client_db; } }));
Object.defineProperty(exports, "site_settings_conf", ({ enumerable: true, get: function () { return db_schema_1.site_settings_conf; } }));
// Load the syncstring extensions to the schema
__webpack_require__(865938);
// Will import some other modules and make them available here, since the code
// used to be in this file, and this is assumed in code elsewhere.  Will change later.
var compute_states_1 = __webpack_require__(977844);
Object.defineProperty(exports, "COMPUTE_STATES", ({ enumerable: true, get: function () { return compute_states_1.COMPUTE_STATES; } }));
var upgrade_spec_1 = __webpack_require__(292148);
Object.defineProperty(exports, "PROJECT_UPGRADES", ({ enumerable: true, get: function () { return upgrade_spec_1.upgrades; } }));
Object.defineProperty(exports, "DEFAULT_QUOTAS", ({ enumerable: true, get: function () { return upgrade_spec_1.DEFAULT_QUOTAS; } }));
Object.defineProperty(exports, "UPGRADES_CURRENT_DATE", ({ enumerable: true, get: function () { return upgrade_spec_1.CURRENT_DATE; } }));
//# sourceMappingURL=schema.js.map

/***/ }),

/***/ 865938:
/***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {

/*
 *  This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
 *  License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
 */
// Schema for synchronized editing of strings.
var misc = __webpack_require__(854006);
var schema = (__webpack_require__(47896).SCHEMA);
schema.syncstrings = {
    primary_key: "string_id",
    fields: {
        string_id: {
            type: "sha1",
            pg_type: "CHAR(40)",
            desc: "id of this synchronized string -- sha1 hash of (project_id and path)",
        },
        project_id: {
            type: "uuid",
            desc: "id of project that this synchronized string belongs to",
        },
        last_active: {
            type: "timestamp",
            desc: 'when a user most-recently "cared" about this syncstring (syncstring will be automatically opened in running project if last_active is sufficiently recent)',
        },
        last_file_change: {
            type: "timestamp",
            desc: "when file on disk last changed not due to save (used by Jupyter sync)",
        },
        path: {
            type: "string",
            desc: "optional path of file being edited",
        },
        deleted: {
            type: "boolean",
            desc: "DEPRECATED (remove this field in a few months from March 2020, when no client is using it)",
        },
        init: {
            type: "map",
            desc: "{time:timestamp, error:?} - info about what happened when project tried to initialize this string",
            date: ["time"],
        },
        save: {
            type: "map",
            desc: "{state:['requested', 'done'], hash:misc.hash_string(what was last saved), expected_hash:?, error:['' or 'error message']}",
        },
        read_only: {
            type: "boolean",
            desc: "true or false, depending on whether this syncstring is readonly or can be edited",
        },
        users: {
            type: "array",
            pg_type: "UUID[]",
            desc: "array of account_id's of those who have edited this string. Index of account_id in this array is used to represent patch authors.",
        },
        last_snapshot: {
            type: "timestamp",
            desc: "timestamp of a recent snapshot; if not given, assume no snapshots.  This is used to restrict the range of patches that have to be downloaded in order start editing the file.",
        },
        snapshot_interval: {
            type: "integer",
            desc: "If m=snapshot_interval is given and there are a total of n patches, then we (some user) should make snapshots at patches m, 2*m, ..., k, where k<=n-m.",
        },
        archived: {
            type: "uuid",
            desc: "if set, then syncstring patches array have been archived in the blob with given uuid.",
        },
        doctype: {
            type: "string",
            desc: "(optional) JSON string describing meaning of the patches (i.e., of this document0 -- e.g., {type:'db', opts:{primary_keys:['id'], string_cols:['name']}}",
        },
        settings: {
            type: "map",
            desc: "Shared (by all users) configuration settings for editing this file (e.g., which spellcheck language to use).",
        },
        huge: {
            type: "boolean",
            desc: "If true, this syncstring contains too many or too large patches to be processed. Hence if this is set, it won't be processed. TODO: implement a better archiving mechanism and then process such 'huge' syncstrings.",
        },
    },
    pg_indexes: ["last_active", "archived"],
    user_query: {
        get: {
            fields: {
                string_id: function (obj, db) {
                    return db.sha1(obj.project_id, obj.path);
                },
                users: null,
                last_snapshot: null,
                snapshot_interval: 300,
                project_id: null,
                path: null,
                deleted: null,
                save: null,
                last_active: null,
                init: null,
                read_only: null,
                last_file_change: null,
                doctype: null,
                archived: null,
                settings: null,
            },
            required_fields: {
                path: true,
                project_id: true,
            },
            check_hook: function (db, obj, account_id, project_id, cb) {
                return db._syncstrings_check(obj, account_id, project_id, function (err) {
                    if (!err) {
                        // only calls cb once patch is unarchived, since new sync
                        // rewrite doesn't use changefeed on database.
                        db.unarchive_patches({ string_id: obj.string_id, cb: cb });
                    }
                    else {
                        cb(err);
                    }
                });
            },
        },
        set: {
            fields: {
                // That string_id must be sha1(project_id,path) means
                // user can only ever query one entry from THIS table;
                // use recent_syncstrings_in_project below to get many.
                string_id: function (obj, db) {
                    return db.sha1(obj.project_id, obj.path);
                },
                users: true,
                last_snapshot: true,
                snapshot_interval: true,
                project_id: true,
                path: true,
                deleted: true,
                save: true,
                last_active: true,
                init: true,
                read_only: true,
                last_file_change: true,
                doctype: true,
                settings: true,
            },
            required_fields: {
                path: true,
                project_id: true,
            },
            check_hook: function (db, obj, account_id, project_id, cb) {
                return db._syncstrings_check(obj, account_id, project_id, cb);
            },
            on_change: function (db, old_val, new_val, account_id, cb) {
                return db._user_set_query_syncstring_change_after(old_val, new_val, account_id, cb);
            },
        },
    },
};
schema.syncstrings.project_query = misc.deep_copy(schema.syncstrings.user_query);
schema.syncstrings_delete = {
    primary_key: schema.syncstrings.primary_key,
    virtual: "syncstrings",
    fields: schema.syncstrings.fields,
    user_query: {
        set: {
            // use set query since selecting only one record by its primary key
            admin: true,
            delete: true,
            options: [{ delete: true }],
            fields: {
                string_id: function (obj, db) {
                    return db.sha1(obj.project_id, obj.path);
                },
                project_id: true,
                path: true,
            },
            required_fields: {
                project_id: true,
                path: true,
            },
            check_hook: function (db, obj, account_id, project_id, cb) {
                return db._syncstrings_check(obj, account_id, project_id, cb);
            },
        },
    },
};
schema.recent_syncstrings_in_project = {
    primary_key: schema.syncstrings.primary_key,
    virtual: "syncstrings",
    fields: {
        string_id: true,
        project_id: true,
        path: true,
        last_active: true,
        deleted: true,
        doctype: true,
    },
    user_query: {
        get: {
            pg_where: function (obj, db) {
                return [
                    {
                        "project_id = $::UUID": obj.project_id,
                        "last_active >= $::TIMESTAMP": misc.minutes_ago(obj.max_age_m),
                    },
                ];
            },
            pg_changefeed: function () {
                // need to do this, since last_active won't
                // be selected automatically, but it is needed by where.
                return {
                    select: {
                        project_id: "UUID",
                        last_active: "TIMESTAMP",
                    },
                };
            },
            fields: {
                project_id: null,
                max_age_m: "null",
                string_id: null,
                last_active: null,
                path: null,
                deleted: null,
                doctype: null,
            },
            required_fields: {
                project_id: true,
                max_age_m: true,
            },
            check_hook: function (db, obj, account_id, project_id, cb) {
                return db._syncstrings_check(obj, account_id, project_id, cb);
            },
        },
    },
};
schema.recent_syncstrings_in_project.project_query =
    schema.recent_syncstrings_in_project.user_query;
schema.patches = {
    primary_key: ["string_id", "time"],
    unique_writes: true,
    pg_indexes: ["time"],
    fields: {
        string_id: {
            pg_type: "CHAR(40)",
            desc: "id of the syncstring that this patch belongs to.",
        },
        time: {
            type: "timestamp",
            desc: "the timestamp of the patch",
        },
        user_id: {
            type: "integer",
            desc: "a nonnegative integer; this is the index into the syncstrings.users array of account_id's",
        },
        patch: {
            type: "string",
            pg_type: "TEXT",
            desc: "JSON string that parses to a patch, which transforms the previous version of the syncstring to this version",
        },
        snapshot: {
            type: "string",
            desc: "Optional -- gives the state of the string at this point in time; this should only be set some time after the patch at this point in time was made. Knowing this snap and all future patches determines all the future versions of the syncstring.",
        },
        sent: {
            type: "timestamp",
            desc: "Optional approximate time at which patch was **actually** sent to the server, which is approximately when it was really made available to other users.  In case of offline editing, patches from days ago might get inserted into the stream, and this makes it possible for the client to know and behave accordingly.  If this is not set then patch was sent about the same time it was created.",
        },
        prev: {
            type: "timestamp",
            desc: "Optional field to indicate patch dependence; if given, don't apply this patch until the patch with timestamp prev has been applied.",
        },
        format: {
            type: "integer",
            desc: "The format of the patch; NULL = compressed dmp patch (for strings); 1 = db-doc patches on objects;",
        },
    },
    user_query: {
        get: {
            fields: {
                string_id: null,
                time: null,
                patch: null,
                user_id: null,
                snapshot: null,
                sent: null,
                prev: null,
                format: null,
            },
            check_hook: function (db, obj, account_id, project_id, cb) {
                // this verifies that user has read access to these patches
                return db._user_get_query_patches_check(obj, account_id, project_id, cb);
            },
        },
        set: {
            fields: {
                string_id: true,
                time: true,
                patch: true,
                user_id: true,
                snapshot: true,
                sent: true,
                prev: true,
                format: true,
            },
            required_fields: {
                string_id: true,
                time: true,
                user_id: true,
            },
            check_hook: function (db, obj, account_id, project_id, cb) {
                // this verifies that user has write access to these patches
                return db._user_set_query_patches_check(obj, account_id, project_id, cb);
            },
            before_change: function (database, old_val, new_val, account_id, cb) {
                if (old_val != null) {
                    // TODO/CRITICAL: not allowing this seems to cause a lot of problems
                    //if old_val.sent and new_val.sent and new_val.sent - 0 != old_val.sent - 0   # CRITICAL: comparing dates here!
                    //    cb("you may not change the sent time once it is set")
                    //    return
                    if (old_val.user_id != null &&
                        new_val.user_id != null &&
                        old_val.user_id !== new_val.user_id) {
                        cb("you may not change the author of a patch from ".concat(old_val.user_id, " to ").concat(new_val.user_id));
                        return;
                    }
                    if (old_val.patch != null &&
                        new_val.patch != null &&
                        old_val.patch !== new_val.patch) {
                        // comparison is ok since it is of *strings*
                        cb("you may not change a patch");
                        return;
                    }
                }
                return cb();
            },
        },
    },
};
schema.patches.project_query = schema.patches.user_query;
/*
TODO: re-implement
* Table to be used for deleting the patches associated to a syncstring.
* Currently only allowed by admin.
schema.patches_delete  =
    primary_key : schema.patches.primary_key
    virtual     : 'patches'
    fields      : schema.patches.fields
    user_query:
        get :  # use get query since selecting a range of records for deletion
            pg_where : (obj, db) ->
                where = ["string_id = $::CHAR(40)" : obj.id[0]]
                if obj.id[1]?
                    where.push("time >= $::TIMESTAMP" : obj.id[1])
                return where
            admin  : true
            delete : true
            fields :
                id   : 'null'
                dummy : null
            check_hook : (db, obj, account_id, project_id, cb) ->
                * this verifies that user has read access to these patches -- redundant with admin requirement above.
                db._user_get_query_patches_check(obj, account_id, project_id, cb)
*/
schema.cursors = {
    primary_key: ["string_id", "user_id"],
    durability: "soft",
    fields: {
        string_id: {
            pg_type: "CHAR(40)",
            desc: "id of the syncstring that this patch belongs to.",
        },
        user_id: {
            type: "integer",
            desc: "id index of the user into the syncstrings users array",
            pg_check: "CHECK (user_id >= 0)",
        },
        locs: {
            type: "array",
            pg_type: "JSONB[]",
            desc: "[{x:?,y:?}, ...]    <-- locations of user_id's cursor(s)",
            pg_check: "NOT NULL",
        },
        time: {
            type: "timestamp",
            desc: "time when these cursor positions were sent out",
        },
    },
    indexes: {
        string_id: ["that.r.row('id')(0)"],
    },
    user_query: {
        get: {
            fields: {
                string_id: null,
                user_id: null,
                locs: null,
                time: null,
            },
            required_fields: {
                string_id: true,
            },
            check_hook: function (db, obj, account_id, project_id, cb) {
                // this verifies that user has read access to these cursors
                return db._user_get_query_cursors_check(obj, account_id, project_id, cb);
            },
        },
        set: {
            fields: {
                string_id: null,
                user_id: null,
                locs: true,
                time: true,
            },
            required_fields: {
                string_id: true,
                user_id: true,
                locs: true,
            },
            check_hook: function (db, obj, account_id, project_id, cb) {
                // this verifies that user has write access to these cursors
                return db._user_set_query_cursors_check(obj, account_id, project_id, cb);
            },
        },
    },
};
schema.cursors.project_query = misc.deep_copy(schema.cursors.user_query);
schema.eval_inputs = {
    primary_key: ["string_id", "time", "user_id"],
    durability: "soft",
    unique_writes: true,
    pg_indexes: ["time"],
    fields: {
        string_id: {
            pg_type: "CHAR(40)",
            desc: "id of the syncdoc that this eval_inputs table is attached to",
        },
        time: {
            type: "timestamp",
            desc: "the timestamp of the input",
        },
        user_id: {
            type: "integer",
            desc: "id index of the user into the syncdoc users array",
            pg_check: "CHECK (user_id >= 0)",
        },
        input: {
            type: "map",
            desc: "For example it could be {program:'sage' or 'sh', input:{code:'...', data:'...', preparse:?, event:'execute_code', output_uuid:?, id:....}}",
        },
    },
    user_query: {
        get: {
            fields: {
                string_id: null,
                time: null,
                user_id: null,
                input: null,
            },
            check_hook: function (db, obj, account_id, project_id, cb) {
                return db._syncstring_access_check(obj.string_id, account_id, project_id, cb);
            },
        },
        set: {
            fields: {
                string_id: true,
                time: true,
                user_id: true,
                input: true,
            },
            required_fields: {
                string_id: true,
                time: true,
                user_id: true,
                input: true,
            },
            check_hook: function (db, obj, account_id, project_id, cb) {
                return db._syncstring_access_check(obj.string_id, account_id, project_id, cb);
            },
        },
    },
};
schema.eval_inputs.project_query = schema.eval_inputs.user_query;
schema.eval_outputs = {
    primary_key: ["string_id", "time", "number"],
    durability: "soft",
    pg_indexes: ["time"],
    fields: {
        string_id: {
            pg_type: "CHAR(40)",
            desc: "id of the syncstring that this patch belongs to.",
        },
        time: {
            type: "timestamp",
            desc: "the timestamp of the output",
        },
        number: {
            type: "integer",
            desc: "output_number starting at 0",
            pg_check: "CHECK (number >= 0)",
        },
        output: {
            type: "map",
        },
    },
    user_query: {
        get: {
            fields: {
                string_id: null,
                time: null,
                number: null,
                output: null,
            },
            check_hook: function (db, obj, account_id, project_id, cb) {
                return db._syncstring_access_check(obj.string_id, account_id, project_id, cb);
            },
        },
        set: {
            fields: {
                string_id: true,
                time: true,
                number: true,
                output: true,
            },
            required_fields: {
                string_id: true,
                time: true,
                number: true,
                output: true,
            },
            check_hook: function (db, obj, account_id, project_id, cb) {
                return db._syncstring_access_check(obj.string_id, account_id, project_id, cb);
            },
        },
    },
};
schema.eval_outputs.project_query = schema.eval_outputs.user_query;
schema.ipywidgets = {
    primary_key: ["string_id", "model_id", "type"],
    durability: "soft",
    // not be stored in the database ever.  Even if we want to persist widget
    // info, we would persist it as metadata in the ipynb file (say), and
    // definitely not in our database.
    fields: {
        string_id: {
            type: "string",
            desc: "id of the syncdoc that this widget is associated to (the Jupyter notebook).",
        },
        model_id: {
            type: "string",
            desc: "the id of the comm that this is data about",
        },
        type: {
            type: "string",
            desc: "type of info associated to this entry in the table:  'value' | 'state' | 'buffers' | 'message'",
        },
        data: {
            type: "map",
            desc: "actual info of the given type about the widget",
        },
    },
    user_query: {
        get: {
            fields: {
                string_id: null,
                model_id: null,
                type: null,
                data: null,
            },
            check_hook: function (db, obj, account_id, project_id, cb) {
                return db._syncstring_access_check(obj.string_id, account_id, project_id, cb);
            },
        },
        set: {
            fields: {
                string_id: true,
                model_id: true,
                type: true,
                data: true,
            },
            required_fields: {
                string_id: true,
                model_id: true,
                type: true,
                data: true,
            },
            check_hook: function (db, obj, account_id, project_id, cb) {
                return db._syncstring_access_check(obj.string_id, account_id, project_id, cb);
            },
        },
    },
};
schema.ipywidgets.project_query = schema.ipywidgets.user_query;
//# sourceMappingURL=syncstring_schema.js.map

/***/ })

};
;